require "yaml" module Hasmenu class Reporter include Printer def initialize(type, options) @type = type @location = options[:location] || Dir.pwd end def get_data(file, field) data = YAML.load_file(file) data.map { |e| e[field] } end def get_folder(files) files.map { |f| File.basename(File.dirname(f)) } end def load_data chains = File.join(@location, "data", "chains.yml") restaurants = File.join(@location, "data", "restaurants.yml") chain_menus = File.join(@location, "data", "menu", "chain", "**", "*.yml") restaurant_menus = File.join(@location, "data", "menu", "restaurant", "**", "*.yml") @yaml_chains = get_data chains, "uid" @yaml_restaurants = get_data restaurants, "uid" @restaurant_chains = get_data restaurants, "chain" @file_chains = get_folder Dir.glob(chain_menus) @file_restaurants = get_folder Dir.glob(restaurant_menus) end def report_chains print_header "List of Chains" print_report(@yaml_chains.sort) end def report_available print_header "Available Chain Menus" print_report(@file_chains.sort) end def report_unavailable print_header "Unavailable Chain Menus" print_report(@restaurant_chains.sort - @file_chains.sort) end def report_approved print_header "Approved Restaurants" print_report(@yaml_restaurants.sort) end def report_unapproved print_header "Unapproved Chains" print_report(@yaml_chains.sort - @restaurant_chains.sort) end def report_progress print_header "Chain Menus in Progress" print_report(@yaml_chains.sort - @file_chains.sort) end def report_done print_header "Restaurant Menus Completed" print_report(@file_restaurants.sort) end def report_all report_chains report_available report_unavailable report_approved report_unapproved report_progress report_done end def report unless File.exist? @location print_invalid_path return end return unless load_data case @type when "chains" report_chains when "available" report_available when "unavailable" report_unavailable when "approved", "restaurants" report_approved when "unapproved" report_unapproved when "progress" report_progress when "done" report_done when "all" report_all else print_invalid_report end end end end