Class: NYCFarmersMarkets::Market
- Inherits:
-
Object
- Object
- NYCFarmersMarkets::Market
- Defined in:
- lib/nyc_farmers_markets/market.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#additional_info ⇒ Object
Returns the value of attribute additional_info.
-
#borough ⇒ Object
Returns the value of attribute borough.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
-
#street_address ⇒ Object
Returns the value of attribute street_address.
-
#website ⇒ Object
Returns the value of attribute website.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_hash(h) ⇒ Object
- .find_by_borough(b) ⇒ Object
- .find_by_zipcode(z) ⇒ Object
- .list_boroughs ⇒ Object
- .list_zipcodes ⇒ Object
- .num_markets_in_borough(b) ⇒ Object
Instance Method Summary collapse
-
#initialize(name: nil, additional_info: nil, street_address: nil, borough: nil, state: "NY", zipcode: nil, website: nil) ⇒ Market
constructor
A new instance of Market.
- #remove_html ⇒ Object
- #save ⇒ Object
- #set_website_from_additional_info ⇒ Object
Constructor Details
#initialize(name: nil, additional_info: nil, street_address: nil, borough: nil, state: "NY", zipcode: nil, website: nil) ⇒ Market
Returns a new instance of Market.
6 7 8 9 10 11 12 13 |
# File 'lib/nyc_farmers_markets/market.rb', line 6 def initialize(name: nil, additional_info: nil, street_address: nil, borough: nil, state: "NY", zipcode: nil, website: nil) @name = name @additional_info = additional_info @street_address = street_address @borough = borough @state = state @zipcode = zipcode end |
Instance Attribute Details
#additional_info ⇒ Object
Returns the value of attribute additional_info.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def additional_info @additional_info end |
#borough ⇒ Object
Returns the value of attribute borough.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def borough @borough end |
#latitude ⇒ Object
Returns the value of attribute latitude.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def state @state end |
#street_address ⇒ Object
Returns the value of attribute street_address.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def street_address @street_address end |
#website ⇒ Object
Returns the value of attribute website.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def website @website end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
2 3 4 |
# File 'lib/nyc_farmers_markets/market.rb', line 2 def zipcode @zipcode end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/nyc_farmers_markets/market.rb', line 15 def self.all @@all end |
.create_from_hash(h) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nyc_farmers_markets/market.rb', line 23 def self.create_from_hash(h) market = self.new( name: h["facilityname"], additional_info: h["facilityaddinfo"], street_address: h["facilitystreetname"], borough: h["facilitycity"], state: h["facilitystate"], zipcode: h["facilityzipcode"] ) market.set_website_from_additional_info market.remove_html market.save market end |
.find_by_borough(b) ⇒ Object
55 56 57 58 59 |
# File 'lib/nyc_farmers_markets/market.rb', line 55 def self.find_by_borough(b) self.all.select do |market| market if market.borough != nil && market.borough.downcase == b.downcase end end |
.find_by_zipcode(z) ⇒ Object
61 62 63 64 65 |
# File 'lib/nyc_farmers_markets/market.rb', line 61 def self.find_by_zipcode(z) self.all.select do |market| market if market.zipcode == z end end |
.list_boroughs ⇒ Object
67 68 69 |
# File 'lib/nyc_farmers_markets/market.rb', line 67 def self.list_boroughs self.all.collect { |market| market.borough }.compact.uniq.sort end |
.list_zipcodes ⇒ Object
71 72 73 |
# File 'lib/nyc_farmers_markets/market.rb', line 71 def self.list_zipcodes self.all.collect { |market| market.zipcode }.compact.uniq.sort end |
.num_markets_in_borough(b) ⇒ Object
75 76 77 |
# File 'lib/nyc_farmers_markets/market.rb', line 75 def self.num_markets_in_borough(b) self.find_by_borough(b).count end |
Instance Method Details
#remove_html ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/nyc_farmers_markets/market.rb', line 46 def remove_html if @additional_info != nil && @additional_info.include?("<") x = @additional_info.index("<") y = @additional_info.length - 1 @additional_info.slice!(x..y) end end |
#save ⇒ Object
19 20 21 |
# File 'lib/nyc_farmers_markets/market.rb', line 19 def save @@all << self end |
#set_website_from_additional_info ⇒ Object
39 40 41 42 43 44 |
# File 'lib/nyc_farmers_markets/market.rb', line 39 def set_website_from_additional_info if @additional_info != nil url_from_info = @additional_info.match(/http:(\w|\/|\.|\&|\=|\?|\_)*</) @website = url_from_info[0].chomp("<").chomp(".") unless url_from_info == nil end end |