class LucaDeal::Product
Public Class Methods
create(obj)
click to toggle source
Save data with hash in Product
format. Simple format is also available as bellows:
{ name: 'item_name(required)', price: 'item_price', qty: 'item_qty', initial: { name: 'item_name', price: 'item_price', qty: 'item_qty' } }
Calls superclass method
# 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
Public Instance Methods
list_name()
click to toggle source
# 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