Class: Warehouse::Item::Code

Inherits:
Struct
  • Object
show all
Defined in:
lib/warehouse/item/code.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#barcodeObject

Returns the value of attribute barcode



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def barcode
  @barcode
end

#codeObject

Returns the value of attribute code



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def code
  @code
end

#code_2Object

Returns the value of attribute code_2



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def code_2
  @code_2
end

#priceObject

Returns the value of attribute price



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def price
  @price
end

#qtyObject

Returns the value of attribute qty



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def qty
  @qty
end

#titleObject

Returns the value of attribute title



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def title
  @title
end

#title_enObject

Returns the value of attribute title_en



3
4
5
# File 'lib/warehouse/item/code.rb', line 3

def title_en
  @title_en
end

Class Method Details

.build(fragment) ⇒ Object



5
6
7
8
9
# File 'lib/warehouse/item/code.rb', line 5

def self.build(fragment)
  qty = fragment["qty"].nil? ? 0 : fragment["qty"].to_i
  Code.new(fragment["code"], fragment["title"], qty, fragment["price"].to_i,
           fragment["barcode"], fragment["code_2"], fragment["title_en"])
end

Instance Method Details

#barcode?Boolean



15
16
17
# File 'lib/warehouse/item/code.rb', line 15

def barcode?
  false
end

#code?Boolean



19
20
21
# File 'lib/warehouse/item/code.rb', line 19

def code?
  true
end

#deep_dupObject



47
48
49
# File 'lib/warehouse/item/code.rb', line 47

def deep_dup
  self.class.new(code, title, qty, price, barcode, code_2, title_en)
end

#is_free?Boolean



11
12
13
# File 'lib/warehouse/item/code.rb', line 11

def is_free?
  price == 0
end

#persisted?Boolean

給 form 用的



52
# File 'lib/warehouse/item/code.rb', line 52

def persisted?; false end

#productObject



53
# File 'lib/warehouse/item/code.rb', line 53

def product; end

#random?Boolean



27
28
29
# File 'lib/warehouse/item/code.rb', line 27

def random?
  false
end

#single?Boolean



31
32
33
# File 'lib/warehouse/item/code.rb', line 31

def single?
  true
end

#to_hObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/warehouse/item/code.rb', line 35

def to_h
  {
    'code' => code,
    'title' => title,
    'qty' => qty,
    'price' => price,
    'barcode' => barcode,
    'code_2' => code_2,
    'title_en' => title_en
  }
end

#typeObject



23
24
25
# File 'lib/warehouse/item/code.rb', line 23

def type
  'single'
end