Class: LucaDeal::Product
- Inherits:
-
LucaRecord::Base
- Object
- LucaRecord::Base
- LucaDeal::Product
- Defined in:
- lib/luca_deal/product.rb
Class Method Summary collapse
-
.create(obj) ⇒ Object
Save data with hash in Product format.
Instance Method Summary collapse
Class Method Details
.create(obj) ⇒ Object
Save data with hash in Product format. Simple format is also available as follows:
{
name: 'item_name(required)', price: 'item_price', qty: 'item_qty',
initial: { name: 'item_name', price: 'item_price', qty: 'item_qty' }
}
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/luca_deal/product.rb', line 25 def self.create(obj) if obj[:name].nil? h = obj else items = [{ 'name' => obj[:name], 'price' => obj[:price] || 0, 'qty' => obj[:qty] || 1 }] if obj[:initial] items << { 'name' => obj.dig(:initial, :name), 'price' => obj.dig(:initial, :price) || 0, 'qty' => obj.dig(:initial, :qty) || 1, 'type' => 'initial' } end h = { 'name' => obj[:name], 'items' => items } end super(h) end |
Instance Method Details
#list_name ⇒ Object
15 16 17 18 |
# File 'lib/luca_deal/product.rb', line 15 def list_name list = self.class.all.map { |dat| parse_current(dat) } YAML.dump(list).tap { |l| puts l } end |