Class: Garden

Inherits:
Object
  • Object
show all
Defined in:
lib/garden.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#boroughObject (readonly)

Returns the value of attribute borough.



5
6
7
# File 'lib/garden.rb', line 5

def borough
  @borough
end

#gardennameObject (readonly)

Returns the value of attribute gardenname.



5
6
7
# File 'lib/garden.rb', line 5

def gardenname
  @gardenname
end

#multipolygonObject (readonly)

Returns the value of attribute multipolygon.



5
6
7
# File 'lib/garden.rb', line 5

def multipolygon
  @multipolygon
end

#parksidObject (readonly)

Returns the value of attribute parksid.



5
6
7
# File 'lib/garden.rb', line 5

def parksid
  @parksid
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/garden.rb', line 5

def status
  @status
end

#zipcodeObject (readonly)

Returns the value of attribute zipcode.



5
6
7
# File 'lib/garden.rb', line 5

def zipcode
  @zipcode
end

Class Method Details

.allObject



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


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