Class: WorldDb::CountryReport

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/worlddb/reports/country_report.rb

Constant Summary

Constants included from Model

Model::Prop, Model::Tag, Model::Tagging

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ CountryReport

pass in country model - why, why not ??



9
10
11
# File 'lib/worlddb/reports/country_report.rb', line 9

def initialize( key )  # pass in country model - why, why not ??
  @key = key
end

Instance Method Details

#reportObject



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"  # print newline

  ## loop over states
  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"  # print newline

    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 << "  %3d munis" % [state.munis.count] -- add munis possilbe??
      buf << "\n"  # print newline
    end # each part
  end # each state

  buf << "\n"  # print newline
  buf << "Total:  "
  buf << "  #{parts_count} parts, "
  buf << "  #{counties_count} counties, "
  buf << "  #{munis_count} munis, "
  buf << "  #{cities_count} cities"
  buf << "\n"  # print newline

  puts buf
end