Class: Yuyi::Menu
- Inherits:
-
Object
- Object
- Yuyi::Menu
- Defined in:
- lib/yuyi/menu.rb
Constant Summary collapse
nil
Instance Attribute Summary collapse
-
#progressbar ⇒ Object
Returns the value of attribute progressbar.
Class Method Summary collapse
-
.add_roll(file_name, klass) ⇒ Object
Add rolls to hash in format of RollInstance Called from Yuyi::Roll when a roll is inherited.
- .find_roll(name, options = {}) ⇒ Object
- .load_from_file ⇒ Object
- .on_the_menu?(roll) ⇒ Boolean
Instance Method Summary collapse
-
#find_roll(name, options = {}) ⇒ Object
Find the best roll match from the sources and require it.
-
#initialize(path) ⇒ Menu
constructor
Create a new menu that stores the raw yaml file along with source, roll, and roll model instances.
- #options(roll) ⇒ Object
Constructor Details
#initialize(path) ⇒ Menu
Create a new menu that stores the raw yaml file along with source, roll, and roll model instances
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yuyi/menu.rb', line 15 def initialize path # make menu instance accessible by the class @@menu = self @rolls = {} @sources = [] # load a yaml file load_from_file path # create objects from the menu set_sources set_roll_models set_rolls end |
Instance Attribute Details
#progressbar ⇒ Object
Returns the value of attribute progressbar.
5 6 7 |
# File 'lib/yuyi/menu.rb', line 5 def @progressbar end |
Class Method Details
.add_roll(file_name, klass) ⇒ Object
Add rolls to hash in format of RollInstance Called from Yuyi::Roll when a roll is inherited
43 44 45 46 47 |
# File 'lib/yuyi/menu.rb', line 43 def self.add_roll file_name, klass unless klass.to_s.include? 'RollModel' rolls[file_name] = klass.new end end |
.find_roll(name, options = {}) ⇒ Object
53 54 55 |
# File 'lib/yuyi/menu.rb', line 53 def self.find_roll name, = {} .send :find_roll, name, end |
.load_from_file ⇒ Object
57 58 59 |
# File 'lib/yuyi/menu.rb', line 57 def self.load_from_file .send :load_from_file end |
.on_the_menu?(roll) ⇒ Boolean
49 50 51 |
# File 'lib/yuyi/menu.rb', line 49 def self. roll .send :on_the_menu?, roll end |
Instance Method Details
#find_roll(name, options = {}) ⇒ Object
Find the best roll match from the sources and require it
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 |
# File 'lib/yuyi/menu.rb', line 63 def find_roll name, = {} return if name # return specific source roll if specified in the menu # if source = [:source] require_roll name, File.join(source, name.to_s) return # look through the sources for the first roll that matches. # sources are listed in the menu in order of priority else @sources.each do |source| if path = source.rolls[name] require_roll name, path return end end end # no roll was found Yuyi.say "You ordered the '#{name}' roll off the menu, but we are fresh out...", :type => :fail Yuyi.say 'Check your menu to make sure a source with your roll is listed.', :type => :warn Yuyi.say end |
#options(roll) ⇒ Object
30 31 32 |
# File 'lib/yuyi/menu.rb', line 30 def roll @yaml[:rolls][roll] || {} end |