class Drawy::Application
Constants
- MENU
To expand the application, just add an entry in the menu and write the corresponding method The entry is of form [‘Text to display’, :method_to_route_to]
Public Class Methods
check()
click to toggle source
# File lib/drawy/application.rb, line 47 def check if Drawy::Engine.result.nil? raise Drawy::InputError, 'You must proceed to drawing before checking someone' end name = Drawy::IO.accept :string, 'Enter the name of the person you want to check:' if name.empty? raise Drawy::InputError, 'Entered name is empty... ignoring.' end result = Drawy::Engine.result[name.downcase] Drawy::IO.show "#{name.capitalize} should buy #{result.capitalize} a gift." end
draw()
click to toggle source
# File lib/drawy/application.rb, line 40 def draw Drawy::Validator.validate_people_format Drawy::IO.show 'Drawing...' Drawy::Engine.draw Drawy::IO.show 'Done! You can now check everyone\'s result.' end
exit()
click to toggle source
# File lib/drawy/application.rb, line 62 def exit Drawy::IO.show 'See you soon' Kernel.exit end
register()
click to toggle source
# File lib/drawy/application.rb, line 33 def register name = Drawy::IO.accept :string, 'Enter the name of the person you want to register:' partner_name = Drawy::IO.accept :string, 'Enter the name of his/her partner (leave blank if the person is single):' Drawy::Validator.validate_uniqueness_of(name, partner_name) Drawy::Engine.add_people [name, partner_name] end
route_for(number = nil)
click to toggle source
# File lib/drawy/application.rb, line 28 def route_for(number = nil) return send(MENU[number-1][1]) if @menu_numbers.include?(number) raise Drawy::InputError, "Please choose a number in #{@menu_numbers}" end
start()
click to toggle source
# File lib/drawy/application.rb, line 16 def start @menu_numbers = *(1..MENU.size) route_for(menu) start end