This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
/
menu.rb
126 lines (119 loc) · 2.15 KB
/
menu.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
class Menu
@@items = [
{
id: 'cappuccino',
name: 'Cappuccino',
options: ['milk'],
},
{
id: 'americano',
name: 'Americano',
options: ['strength'],
},
{
id: 'gibraltar',
name: 'Gibraltar',
options: ['milk'],
},
{
id: 'latte',
name: 'Latte',
options: ['milk'],
},
{
id: 'lavlatte',
name: 'Lavendar Latte',
options: ['milk'],
},
{
id: 'mintlatte',
name: 'Mint Latte',
options: ['milk'],
},
{
id: 'espresso',
name: 'Espresso',
options: ['strength'],
},
{
id: 'espressomach',
name: 'Espresso Macchiato',
options: ['milk'],
},
{
id: 'mocha',
name: 'Mocha',
options: ['milk'],
},
{
id: 'tea',
name: 'Hot Tea',
options: ['milk'],
}
]
@@options = [
{
id: 'strength',
choices: [
{
id: 'single',
name: 'Single',
},
{
id: 'double',
name: 'Double',
},
{
id: 'triple',
name: 'Triple',
},
{
id: 'quad',
name: 'Quad',
},
],
},
{
id: 'milk',
choices: [
{
id: 'whole',
name: 'Whole',
},
{
id: 'lowfat',
name: 'Low fat',
},
{
id: 'almond',
name: 'Almond',
},
{
id: 'soy',
name: 'Soy',
},
],
}
]
def self.items
@@items
end
def self.options
@@options
end
def self.list_of_types
self.items.map { |i| ({ text: i[:name], value: i[:id] })}
end
def self.list_of_choices_for_option(option_id)
choices = self.options.find {|o| o[:id] == option_id}[:choices]
return choices.map { |c| ({ text: c[:name], value: c[:id]})}
end
def self.choice_name_for_id(option_id, choice_id)
option = self.options.find {|o| o[:id] == option_id}
if !option.nil?
choice = option[:choices].find {|c| c[:id] == choice_id}
return choice[:name]
end
return false
end
end