Class: Livingsocial2::Deal

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#categoriesObject

Returns the value of attribute categories.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def categories
  @categories
end

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def content
  @content
end

#country_codeObject

Returns the value of attribute country_code.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def country_code
  @country_code
end

#deal_typeObject

Returns the value of attribute deal_type.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def deal_type
  @deal_type
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def description
  @description
end

#detailsObject

Returns the value of attribute details.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def details
  @details
end

#featureTypeObject

Returns the value of attribute featureType.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def featureType
  @featureType
end

#image_urlObject

Returns the value of attribute image_url.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def image_url
  @image_url
end

Returns the value of attribute link.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def link
  @link
end

#long_titleObject

Returns the value of attribute long_title.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def long_title
  @long_title
end

#ls_idObject

Returns the value of attribute ls_id.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def ls_id
  @ls_id
end

#market_idObject

Returns the value of attribute market_id.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def market_id
  @market_id
end

#market_locationObject

Returns the value of attribute market_location.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def market_location
  @market_location
end

#market_nameObject

Returns the value of attribute market_name.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def market_name
  @market_name
end

#merchandise_typeObject

Returns the value of attribute merchandise_type.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def merchandise_type
  @merchandise_type
end

#merchantObject

Returns the value of attribute merchant.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def merchant
  @merchant
end

#merchant_typeObject

Returns the value of attribute merchant_type.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def merchant_type
  @merchant_type
end

#nationalObject

Returns the value of attribute national.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def national
  @national
end

#offer_ends_atObject

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_countObject

Returns the value of attribute order_count.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def order_count
  @order_count
end

#priceObject

Returns the value of attribute price.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def price
  @price
end

#publishedObject

Returns the value of attribute published.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def published
  @published
end

#savingsObject

Returns the value of attribute savings.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def savings
  @savings
end

#sold_outObject

Returns the value of attribute sold_out.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def sold_out
  @sold_out
end

#subtitleObject

Returns the value of attribute subtitle.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/livingsocial2/deal.rb', line 9

def title
  @title
end

#valueObject

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