Class: BadASS::Sale

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sale_hash) ⇒ Sale

Create a Sale object using a hash from the API.



3
4
5
6
7
8
9
# File 'lib/badass/sale.rb', line 3

def initialize(sale_hash)
  @title = sale_hash['title']
  @description = JSON.parse(sale_hash['content'])['blocks'].map { |x| x['text'] }.join("\n")
  @image = sale_hash['image']['url']
  @start_date = Date.rfc3339(sale_hash['startDate']) rescue nil
  @end_date = Date.rfc3339(sale_hash['endDate']) rescue nil
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/badass/sale.rb', line 12

def description
  @description
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



15
16
17
# File 'lib/badass/sale.rb', line 15

def end_date
  @end_date
end

#imageObject (readonly)

Returns the value of attribute image.



13
14
15
# File 'lib/badass/sale.rb', line 13

def image
  @image
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



14
15
16
# File 'lib/badass/sale.rb', line 14

def start_date
  @start_date
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/badass/sale.rb', line 11

def title
  @title
end