forked from hanachin/MacDonaldBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calorie.rb
74 lines (60 loc) · 1.39 KB
/
calorie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#encoding: utf-8
require 'yaml'
# http://www.mcdonalds.co.jp/quality/allergy_Nutrition/nutrient2.php?id=1
# こぴぺ: $.makeArray($('tr').map(function (){return [$(this).find('td.item').text(), $(this).find('td:nth-child(3)').text()]}))
# 理想
# Order.new('グラころ2つ、ナゲット1個').each {|item, calorie|
# # 1. グラコロ
# # 2. グラコロ
# # 3. ナゲット
# }
# - セット
# - サイズ
# - 個数
# - 味
class FastFood
class << self
def calorie_table
@calorie_table ||= YAML.load_file 'calorie.yaml'
end
def menu_names
@menu_names ||= calorie_table.keys
end
def alias_menu_name_table
@alias_menu_name_table ||= YAML.load_file 'alias.yaml'
end
def menu_name(name)
if menu_names.include? name
name
else
alias_menu_name_table[name]
end
end
def menu_calorie(name)
calorie_table[name]
end
def many_menus?(order)
order =~ /[、 ]/
end
def menu order
n = menu_name order
{n => menu_calorie(n)}
end
def take_menu orders
orders.include?(menu_names)
end
def menus order
alias_menu_name_table.keys
order.split(/[、 ]/).inject({}) {|orders, order|
orders.merge menu order
}
end
def calorie(order)
if many_menus? order
menus order
else
menu order
end
end
end
end