Class: NycGreenMarkets::GreenMarket
- Inherits:
-
Object
- Object
- NycGreenMarkets::GreenMarket
- Defined in:
- lib/nyc_green_markets.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Class Method Summary collapse
- .all ⇒ Object
- .create_markets(markets_array) ⇒ Object
- .find_by(search_term) ⇒ Object
- .where(search_term) ⇒ Object
Instance Method Summary collapse
-
#initialize(market) ⇒ GreenMarket
constructor
A new instance of GreenMarket.
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
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/nyc_green_markets.rb', line 6 def address @address end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
6 7 8 |
# File 'lib/nyc_green_markets.rb', line 6 def city @city end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/nyc_green_markets.rb', line 6 def name @name end |
#zip ⇒ Object (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
.all ⇒ Object
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 |