Class: Gilt::Sku

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

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

#attributesObject



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/gilt/sku.rb', line 22

def for_sale?
  inventory_status == FOR_SALE
end

#idObject



14
15
16
# File 'lib/gilt/sku.rb', line 14

def id
  @sku["id"].to_i
end

#inventory_statusObject



18
19
20
# File 'lib/gilt/sku.rb', line 18

def inventory_status
  @sku["inventory_status"]
end

#msrp_priceObject



34
35
36
# File 'lib/gilt/sku.rb', line 34

def msrp_price
  to_dollars @sku["msrp_price"]
end

#reserved?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gilt/sku.rb', line 30

def reserved?
  inventory_status == RESERVED
end

#sale?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/gilt/sku.rb', line 58

def sale?
  sale_price != msrp_price
end

#sale_priceObject



38
39
40
# File 'lib/gilt/sku.rb', line 38

def sale_price
  to_dollars @sku["sale_price"]
end

#shipping_surchargeObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/gilt/sku.rb', line 26

def sold_out?
  inventory_status == SOLD_OUT
end

#subtotalObject



47
48
49
# File 'lib/gilt/sku.rb', line 47

def subtotal
  sale_price + shipping_surcharge
end