Class: Livingsocial2::Deal
- Inherits:
-
Object
- Object
- Livingsocial2::Deal
- Defined in:
- lib/livingsocial2/deal.rb
Constant Summary collapse
- DEAL_TYPES =
{ family: 'FamiliesDeal', local: 'LocalDeal', at_home: 'AtHomeDeal', gourmet: 'GourmetDeal', all: 'all' }
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#content ⇒ Object
Returns the value of attribute content.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#deal_type ⇒ Object
Returns the value of attribute deal_type.
-
#description ⇒ Object
Returns the value of attribute description.
-
#details ⇒ Object
Returns the value of attribute details.
-
#featureType ⇒ Object
Returns the value of attribute featureType.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#link ⇒ Object
Returns the value of attribute link.
-
#long_title ⇒ Object
Returns the value of attribute long_title.
-
#ls_id ⇒ Object
Returns the value of attribute ls_id.
-
#market_id ⇒ Object
Returns the value of attribute market_id.
-
#market_location ⇒ Object
Returns the value of attribute market_location.
-
#market_name ⇒ Object
Returns the value of attribute market_name.
-
#merchandise_type ⇒ Object
Returns the value of attribute merchandise_type.
-
#merchant ⇒ Object
Returns the value of attribute merchant.
-
#merchant_type ⇒ Object
Returns the value of attribute merchant_type.
-
#national ⇒ Object
Returns the value of attribute national.
-
#offer_ends_at ⇒ Object
Returns the value of attribute offer_ends_at.
-
#order_count ⇒ Object
Returns the value of attribute order_count.
-
#price ⇒ Object
Returns the value of attribute price.
-
#published ⇒ Object
Returns the value of attribute published.
-
#savings ⇒ Object
Returns the value of attribute savings.
-
#sold_out ⇒ Object
Returns the value of attribute sold_out.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#title ⇒ Object
Returns the value of attribute title.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .find_by_ls_market(deal_type, market) ⇒ Object
- .find_deals_for(deal_type) ⇒ Object
- .find_near(deal_type, lat, long, distance = 3) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Deal
constructor
A new instance of Deal.
Constructor Details
#initialize(attributes) ⇒ Deal
Returns a new instance of Deal.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/livingsocial2/deal.rb', line 16 def initialize(attributes) self.ls_id = attributes['ls_id'] self.published = attributes['published'] self.link = attributes['link'] self.title = attributes['title'] self.long_title = attributes['long_title'] self.deal_type = attributes['deal_type'] self.merchandise_type = attributes['merchandise_type'] self.market_id = attributes['market_id'] self.market_name = attributes['market_name'] self.market_location = attributes['market_location'] self.featureType = attributes['featureType'] self.country_code = attributes['country_code'] self.subtitle = attributes['subtitle'] self.offer_ends_at = attributes['offer_ends_at'] self.price = attributes['price'] self.value = attributes['value'] self.savings = attributes['savings'] self.order_count = attributes['order_count'] self.merchant_type = attributes['merchant_type'] self.image_url = attributes['image_url'] self.categories = attributes['categories'] self.sold_out = attributes['sold_out'] self.national = attributes['national'] self.description = attributes['description'] self.details = attributes['details'] self.content = attributes['content'] self.merchant = attributes['merchant'] end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def categories @categories end |
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def content @content end |
#country_code ⇒ Object
Returns the value of attribute country_code.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def country_code @country_code end |
#deal_type ⇒ Object
Returns the value of attribute deal_type.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def deal_type @deal_type end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def description @description end |
#details ⇒ Object
Returns the value of attribute details.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def details @details end |
#featureType ⇒ Object
Returns the value of attribute featureType.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def featureType @featureType end |
#image_url ⇒ Object
Returns the value of attribute image_url.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def image_url @image_url end |
#link ⇒ Object
Returns the value of attribute link.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def link @link end |
#long_title ⇒ Object
Returns the value of attribute long_title.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def long_title @long_title end |
#ls_id ⇒ Object
Returns the value of attribute ls_id.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def ls_id @ls_id end |
#market_id ⇒ Object
Returns the value of attribute market_id.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def market_id @market_id end |
#market_location ⇒ Object
Returns the value of attribute market_location.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def market_location @market_location end |
#market_name ⇒ Object
Returns the value of attribute market_name.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def market_name @market_name end |
#merchandise_type ⇒ Object
Returns the value of attribute merchandise_type.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def merchandise_type @merchandise_type end |
#merchant ⇒ Object
Returns the value of attribute merchant.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def merchant @merchant end |
#merchant_type ⇒ Object
Returns the value of attribute merchant_type.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def merchant_type @merchant_type end |
#national ⇒ Object
Returns the value of attribute national.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def national @national end |
#offer_ends_at ⇒ Object
Returns the value of attribute offer_ends_at.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def offer_ends_at @offer_ends_at end |
#order_count ⇒ Object
Returns the value of attribute order_count.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def order_count @order_count end |
#price ⇒ Object
Returns the value of attribute price.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def price @price end |
#published ⇒ Object
Returns the value of attribute published.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def published @published end |
#savings ⇒ Object
Returns the value of attribute savings.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def savings @savings end |
#sold_out ⇒ Object
Returns the value of attribute sold_out.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def sold_out @sold_out end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def subtitle @subtitle end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def title @title end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/livingsocial2/deal.rb', line 9 def value @value end |
Class Method Details
.find_by_ls_market(deal_type, market) ⇒ Object
54 55 56 57 |
# File 'lib/livingsocial2/deal.rb', line 54 def self.find_by_ls_market(deal_type, market) valid_deals = find_deals_for(DEAL_TYPES[deal_type]).where(title: market.capitalize) valid_deals.map { |deal| new(deal.attributes) } end |
.find_deals_for(deal_type) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/livingsocial2/deal.rb', line 46 def self.find_deals_for(deal_type) if deal_type == 'all' LivingSocialDeal else LivingSocialDeal.where(deal_type: deal_type) end end |
.find_near(deal_type, lat, long, distance = 3) ⇒ Object
59 60 61 62 |
# File 'lib/livingsocial2/deal.rb', line 59 def self.find_near(deal_type, lat, long, distance=3) valid_deals = find_deals_for(DEAL_TYPES[deal_type]).where(:market_location => { "$near" => [lat, long], "$maxDistance" => distance.fdiv(69) }) valid_deals.map { |deal| new(deal.attributes) } end |