Class: Hasmenu::Reporter
- Inherits:
-
Object
show all
- Includes:
- Printer
- Defined in:
- lib/hasmenu/reporter.rb
Instance Method Summary
collapse
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) ⇒ Reporter
Returns a new instance of Reporter.
7
8
9
10
|
# File 'lib/hasmenu/reporter.rb', line 7
def initialize(type, options)
@type = type
@location = options[:location] || Dir.pwd
end
|
Instance Method Details
#get_data(file, field) ⇒ Object
12
13
14
15
|
# File 'lib/hasmenu/reporter.rb', line 12
def get_data(file, field)
data = YAML.load_file(file)
data.map { |e| e[field] }
end
|
#get_folder(files) ⇒ Object
17
18
19
|
# File 'lib/hasmenu/reporter.rb', line 17
def get_folder(files)
files.map { |f| File.basename(File.dirname(f)) }
end
|
#load_data ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/hasmenu/reporter.rb', line 21
def load_data
chains = File.join(@location, "data", "chains.yml")
restaurants = File.join(@location, "data", "restaurants.yml")
= File.join(@location, "data", "menu", "chain", "**", "*.yml")
= 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()
@file_restaurants = get_folder Dir.glob()
end
|
#report ⇒ Object
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
|
# File 'lib/hasmenu/reporter.rb', line 79
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
|
#report_all ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/hasmenu/reporter.rb', line 69
def report_all
report_chains
report_available
report_unavailable
report_approved
report_unapproved
report_progress
report_done
end
|
#report_approved ⇒ Object
49
50
51
52
|
# File 'lib/hasmenu/reporter.rb', line 49
def report_approved
"Approved Restaurants"
print_report(@yaml_restaurants.sort)
end
|
#report_available ⇒ Object
39
40
41
42
|
# File 'lib/hasmenu/reporter.rb', line 39
def report_available
"Available Chain Menus"
print_report(@file_chains.sort)
end
|
#report_chains ⇒ Object
34
35
36
37
|
# File 'lib/hasmenu/reporter.rb', line 34
def report_chains
"List of Chains"
print_report(@yaml_chains.sort)
end
|
#report_done ⇒ Object
64
65
66
67
|
# File 'lib/hasmenu/reporter.rb', line 64
def report_done
"Restaurant Menus Completed"
print_report(@file_restaurants.sort)
end
|
#report_progress ⇒ Object
59
60
61
62
|
# File 'lib/hasmenu/reporter.rb', line 59
def report_progress
"Chain Menus in Progress"
print_report(@yaml_chains.sort - @file_chains.sort)
end
|
#report_unapproved ⇒ Object
54
55
56
57
|
# File 'lib/hasmenu/reporter.rb', line 54
def report_unapproved
"Unapproved Chains"
print_report(@yaml_chains.sort - @restaurant_chains.sort)
end
|
#report_unavailable ⇒ Object
44
45
46
47
|
# File 'lib/hasmenu/reporter.rb', line 44
def report_unavailable
"Unavailable Chain Menus"
print_report(@restaurant_chains.sort - @file_chains.sort)
end
|