Class: Hola::Product::Inventory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hola/product/inventory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInventory

Returns a new instance of Inventory.



17
18
19
20
21
22
23
# File 'lib/hola/product/inventory.rb', line 17

def initialize
  @products = [
    Product.new(name: "Green Tea", price: 3.11, offer: "GetOneFree"),
    Product.new(name: "Strawberries", price: 5.0, offer: "StrawberryBulkDiscount"),
    Product.new(name: "Coffee", price: 11.23, offer: "TwoThirdsBulkDiscount")
  ]
end

Instance Attribute Details

#productsObject (readonly)

Returns the value of attribute products.



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

def products
  @products
end

Instance Method Details

#find_product(id) ⇒ Object



25
26
27
# File 'lib/hola/product/inventory.rb', line 25

def find_product(id)
  products.find { |p| p.id == id }
end