Class: BadASS::Sale

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

Overview

Base class containing a Bad Dragon sale and it's attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sale_hash) ⇒ Sale

Create a Sale object using a hash from the API.


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

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

#descriptionString (readonly)


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

def description
  @description
end

#end_dateDate (readonly)


22
23
24
# File 'lib/badass/sale.rb', line 22

def end_date
  @end_date
end

#imageString (readonly)


18
19
20
# File 'lib/badass/sale.rb', line 18

def image
  @image
end

#start_dateDate (readonly)


20
21
22
# File 'lib/badass/sale.rb', line 20

def start_date
  @start_date
end

#titleString (readonly)


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

def title
  @title
end