Class: NycGreenMarkets::GreenMarket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(market) ⇒ GreenMarket

Returns a new instance of GreenMarket.



8
9
10
11
12
13
# File 'lib/nyc_green_markets.rb', line 8

def initialize(market)
  @name = market['facilityname']
  @address = market['facilitystreetname']
  @city = market['facilitycity']
  @zip = market['facilityzipcode']
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



6
7
8
# File 'lib/nyc_green_markets.rb', line 6

def address
  @address
end

#cityObject (readonly)

Returns the value of attribute city.



6
7
8
# File 'lib/nyc_green_markets.rb', line 6

def city
  @city
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/nyc_green_markets.rb', line 6

def name
  @name
end

#zipObject (readonly)

Returns the value of attribute zip.



6
7
8
# File 'lib/nyc_green_markets.rb', line 6

def zip
  @zip
end

Class Method Details

.allObject



15
16
17
18
19
# File 'lib/nyc_green_markets.rb', line 15

def self.all
  markets_array = Unirest.get('https://data.cityofnewyork.us/resource/cw3p-q2v6.json').body
  markets = []
  create_markets(markets_array)
end

.create_markets(markets_array) ⇒ Object



37
38
39
# File 'lib/nyc_green_markets.rb', line 37

def self.create_markets(markets_array)
  markets_array.map { |market| GreenMarket.new(market)}
end

.find_by(search_term) ⇒ Object



28
29
30
31
32
33
# File 'lib/nyc_green_markets.rb', line 28

def self.find_by(search_term)
  key = search_term.keys.first.to_s
  value = search_term.values.first
  market = Unirest.get("https://data.cityofnewyork.us/resource/cw3p-q2v6.json?#{key}=#{value}").body.first
  GreenMarket.new(market)
end

.where(search_term) ⇒ Object



21
22
23
24
25
26
# File 'lib/nyc_green_markets.rb', line 21

def self.where(search_term)
  key = search_term.keys.first.to_s
  value = search_term.values.first
  markets_array = Unirest.get("https://data.cityofnewyork.us/resource/cw3p-q2v6.json?#{key}=#{value}").body
  create_markets(markets_array)
end