Class: Gilt::Sku
- Inherits:
-
Object
- Object
- Gilt::Sku
- Defined in:
- lib/gilt/sku.rb
Constant Summary collapse
- CURRENCY =
"USD"
- FOR_SALE =
"for sale"
- RESERVED =
"reserved"
- SOLD_OUT =
"sold out"
Instance Method Summary collapse
- #attributes ⇒ Object
- #for_sale? ⇒ Boolean
- #id ⇒ Object
-
#initialize(sku_response) ⇒ Sku
constructor
A new instance of Sku.
- #inventory_status ⇒ Object
- #msrp_price ⇒ Object
- #reserved? ⇒ Boolean
- #sale? ⇒ Boolean
- #sale_price ⇒ Object
- #shipping_surcharge ⇒ Object
- #sold_out? ⇒ Boolean
- #subtotal ⇒ Object
Constructor Details
#initialize(sku_response) ⇒ Sku
Returns a new instance of Sku.
10 11 12 |
# File 'lib/gilt/sku.rb', line 10 def initialize(sku_response) @sku = sku_response end |
Instance Method Details
#attributes ⇒ Object
51 52 53 54 55 56 |
# File 'lib/gilt/sku.rb', line 51 def attributes pairs = @sku["attributes"].map do |pair| [pair["name"].intern, pair["value"]] end Hash[pairs] end |
#for_sale? ⇒ Boolean
22 23 24 |
# File 'lib/gilt/sku.rb', line 22 def for_sale? inventory_status == FOR_SALE end |
#id ⇒ Object
14 15 16 |
# File 'lib/gilt/sku.rb', line 14 def id @sku["id"].to_i end |
#inventory_status ⇒ Object
18 19 20 |
# File 'lib/gilt/sku.rb', line 18 def inventory_status @sku["inventory_status"] end |
#msrp_price ⇒ Object
34 35 36 |
# File 'lib/gilt/sku.rb', line 34 def msrp_price to_dollars @sku["msrp_price"] end |
#reserved? ⇒ Boolean
30 31 32 |
# File 'lib/gilt/sku.rb', line 30 def reserved? inventory_status == RESERVED end |
#sale? ⇒ Boolean
58 59 60 |
# File 'lib/gilt/sku.rb', line 58 def sale? sale_price != msrp_price end |
#sale_price ⇒ Object
38 39 40 |
# File 'lib/gilt/sku.rb', line 38 def sale_price to_dollars @sku["sale_price"] end |
#shipping_surcharge ⇒ Object
42 43 44 45 |
# File 'lib/gilt/sku.rb', line 42 def shipping_surcharge surcharge = @sku["shipping_surcharge"] to_dollars surcharge.nil? ? 0 : surcharge end |
#sold_out? ⇒ Boolean
26 27 28 |
# File 'lib/gilt/sku.rb', line 26 def sold_out? inventory_status == SOLD_OUT end |
#subtotal ⇒ Object
47 48 49 |
# File 'lib/gilt/sku.rb', line 47 def subtotal sale_price + shipping_surcharge end |