Class: Hola::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/hola/product.rb,
lib/hola/product/selector.rb,
lib/hola/product/inventory.rb

Defined Under Namespace

Classes: Inventory, Selector

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, price:, offer: "") ⇒ Product

Returns a new instance of Product.



25
26
27
28
29
30
# File 'lib/hola/product.rb', line 25

def initialize(name:, price:, offer: "")
  @id = SecureRandom.uuid
  @name = name
  @price = Utils::Money.parse(price)
  @offer = offer
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/hola/product.rb', line 23

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/hola/product.rb', line 23

def name
  @name
end

#offerObject

Returns the value of attribute offer.



23
24
25
# File 'lib/hola/product.rb', line 23

def offer
  @offer
end

#priceObject (readonly)

Returns the value of attribute price.



23
24
25
# File 'lib/hola/product.rb', line 23

def price
  @price
end

Class Method Details

.currencyObject



18
19
20
# File 'lib/hola/product.rb', line 18

def currency
  ""
end

.find(id) ⇒ Object



14
15
16
# File 'lib/hola/product.rb', line 14

def find(id)
  Inventory.instance.find_product(id)
end

.listObject



10
11
12
# File 'lib/hola/product.rb', line 10

def list
  Inventory.instance.products
end

Instance Method Details

#apply_offer(name) ⇒ Object



40
41
42
# File 'lib/hola/product.rb', line 40

def apply_offer(name)
  self.offer = name
end

#offer?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/hola/product.rb', line 32

def offer?
  !offer.empty?
end

#to_optionObject



36
37
38
# File 'lib/hola/product.rb', line 36

def to_option
  {name: title, value: id}
end