Class: Garden
- Inherits:
-
Object
- Object
- Garden
- Defined in:
- lib/garden.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#borough ⇒ Object
readonly
Returns the value of attribute borough.
-
#gardenname ⇒ Object
readonly
Returns the value of attribute gardenname.
-
#multipolygon ⇒ Object
readonly
Returns the value of attribute multipolygon.
-
#parksid ⇒ Object
readonly
Returns the value of attribute parksid.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#zipcode ⇒ Object
readonly
Returns the value of attribute zipcode.
Class Method Summary collapse
- .all ⇒ Object
- .filter_by_borough(borough) ⇒ Object
- .filter_by_status(status) ⇒ Object
- .filter_by_zip(zipcode) ⇒ Object
- .print_top_zipcodes(borough) ⇒ Object
- .translate_borough(borough) ⇒ Object
- .zipcode_hash(borough) ⇒ Object
Instance Method Summary collapse
-
#initialize(borough, gardenname, multipolygon, parksid, status, zipcode) ⇒ Garden
constructor
A new instance of Garden.
Constructor Details
#initialize(borough, gardenname, multipolygon, parksid, status, zipcode) ⇒ Garden
Returns a new instance of Garden.
9 10 11 12 13 14 15 16 17 |
# File 'lib/garden.rb', line 9 def initialize (borough, gardenname, multipolygon, parksid, status, zipcode) @borough = borough @gardenname = gardenname @multipolygon = multipolygon @parksid = parksid @status = status @zipcode = zipcode @@all << self end |
Instance Attribute Details
#borough ⇒ Object (readonly)
Returns the value of attribute borough.
5 6 7 |
# File 'lib/garden.rb', line 5 def borough @borough end |
#gardenname ⇒ Object (readonly)
Returns the value of attribute gardenname.
5 6 7 |
# File 'lib/garden.rb', line 5 def gardenname @gardenname end |
#multipolygon ⇒ Object (readonly)
Returns the value of attribute multipolygon.
5 6 7 |
# File 'lib/garden.rb', line 5 def multipolygon @multipolygon end |
#parksid ⇒ Object (readonly)
Returns the value of attribute parksid.
5 6 7 |
# File 'lib/garden.rb', line 5 def parksid @parksid end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/garden.rb', line 5 def status @status end |
#zipcode ⇒ Object (readonly)
Returns the value of attribute zipcode.
5 6 7 |
# File 'lib/garden.rb', line 5 def zipcode @zipcode end |
Class Method Details
.all ⇒ Object
19 20 21 |
# File 'lib/garden.rb', line 19 def self.all @@all end |
.filter_by_borough(borough) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/garden.rb', line 39 def self.filter_by_borough(borough) if borough == "all" @@all else @@all.select {|g| g.borough == borough} end #select creates a new array with all gardens (object IDs) that match it end |
.filter_by_status(status) ⇒ Object
53 54 55 |
# File 'lib/garden.rb', line 53 def self.filter_by_status(status) @@all.select {|g| g.status == status} end |
.filter_by_zip(zipcode) ⇒ Object
49 50 51 |
# File 'lib/garden.rb', line 49 def self.filter_by_zip(zipcode) @@all.select {|g| g.zipcode == zipcode} end |
.print_top_zipcodes(borough) ⇒ Object
68 69 70 71 |
# File 'lib/garden.rb', line 68 def self.print_top_zipcodes(borough) highest_sorted_zipcodes = self.zipcode_hash(borough).sort_by{|k,v| v}.reverse highest_sorted_zipcodes.first(5).map {|k,v| puts "#{"#{v}".magenta} gardens in #{"#{k}".yellow}".indent(4)} end |
.translate_borough(borough) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/garden.rb', line 24 def self.translate_borough(borough) if borough == "B" "Brooklyn" elsif borough == "X" "the Bronx" elsif borough == "M" "Manhattan" elsif borough == "Q" "Queens" elsif borough == "R" "Staten Island" end end |
.zipcode_hash(borough) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/garden.rb', line 58 def self.zipcode_hash(borough) zipcode_count = {} self.filter_by_borough(borough).map do |g| zipcode_count[g.zipcode] = self.filter_by_zip(g.zipcode).count end zipcode_count end |