Class: Hasmenu::Builder
- Inherits:
-
Object
- Object
- Hasmenu::Builder
- Includes:
- Printer
- Defined in:
- lib/hasmenu/builder.rb
Instance Method Summary collapse
- #build(uid, menu_uid) ⇒ Object
- #build_menu(restaurant, menu_uid) ⇒ Object
-
#initialize(type, options) ⇒ Builder
constructor
A new instance of Builder.
Methods included from Printer
#print_build_for, #print_build_start, #print_format_for, #print_format_start, #print_header, #print_invalid_build, #print_invalid_format, #print_invalid_path, #print_invalid_report, #print_invalid_sequence, #print_invalid_version, #print_report, #print_warn_repeats
Constructor Details
#initialize(type, options) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 |
# File 'lib/hasmenu/builder.rb', line 7 def initialize(type, ) @type = type @location = [:location] || Dir.pwd end |
Instance Method Details
#build(uid, menu_uid) ⇒ Object
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 |
# File 'lib/hasmenu/builder.rb', line 34 def build(uid, ) restaurants_yml = File.join(@location, "data", "restaurants.yml") unless File.exist? restaurants_yml print_invalid_path return end restaurants = YAML.load_file(restaurants_yml) case @type when "chain" restaurants.select! { |r| r["chain"] == uid } when "restaurant" restaurants.select! { |r| r["uid"] == uid } when "all" restaurants else print_invalid_build return end print_build_start restaurants.each do |restaurant| restaurant, end end |
#build_menu(restaurant, menu_uid) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hasmenu/builder.rb', line 12 def (restaurant, ) output = {} output["restaurant"] = restaurant chain = restaurant["chain"] = ? "#{}.yml" : "*.yml" pattern = File.join(@location, "data", "menu", "chain", chain, ) Dir.glob(pattern).each do || = YAML.load_file() output["restaurant"]["menus"] = ["chain"]["menus"] restaurant_dir = File.join(@location, "data", "menu", "restaurant", restaurant["uid"]) FileUtils.mkdir_p(restaurant_dir) unless File.directory?(restaurant_dir) = File.join(restaurant_dir, File.basename()) File.open(, "w") { |f| f.write output.to_yaml } print_build_for restaurant["uid"] end end |