14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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/worlddb/reports/country_report.rb', line 14
def report
buf = ''
c = Country.find_by!( key: @key)
buf << "Country Report for #{c.name} (#{c.key}), "
buf << "#{c.states.count} states"
buf << "\n\n"
parts_count = 0
counties_count = 0
munis_count = 0
cities_count = 0
c.states.each do |state|
buf << "%-36s |" % ["#{state.name} (#{state.key})"]
buf << " %3d parts" % [state.parts.count]
buf << " %3d counties" % [state.counties.count]
buf << " %3d munis" % [state.munis.count]
buf << " %3d cities" % [state.cities.count]
buf << "\n"
parts_count += state.parts.count
counties_count += state.counties.count
munis_count += state.munis.count
cities_count += state.cities.count
state.parts.each do |part|
buf << " %-34s |" % ["#{part.name} (#{part.key})"]
buf << " %3d counties" % [part.counties.count]
buf << "\n" end end
buf << "\n" buf << "Total: "
buf << " #{parts_count} parts, "
buf << " #{counties_count} counties, "
buf << " #{munis_count} munis, "
buf << " #{cities_count} cities"
buf << "\n"
puts buf
end
|