Class: Moo::Model::Pack

Inherits:
Object show all
Defined in:
lib/moo/model/pack.rb

Constant Summary collapse

PRODUCT_CODES =
['businesscard', 'minicard', 'postcard', 'holidaycard', 'sticker'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Pack

Returns a new instance of Pack.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
# File 'lib/moo/model/pack.rb', line 8

def initialize
  @cards = []
  @sides = []
  @product_version = 0
  yield self if block_given?
end

Instance Attribute Details

#cardsObject

Returns the value of attribute cards.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def cards
  @cards
end

#image_basketObject

Returns the value of attribute image_basket.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def image_basket
  @image_basket
end

#num_cardsObject

Returns the value of attribute num_cards.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def num_cards
  @num_cards
end

#product_codeObject

Returns the value of attribute product_code.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def product_code
  @product_code
end

#product_versionObject

Returns the value of attribute product_version.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def product_version
  @product_version
end

#sidesObject

Returns the value of attribute sides.



4
5
6
# File 'lib/moo/model/pack.rb', line 4

def sides
  @sides
end

Instance Method Details

#fill_side_numsObject



41
42
43
44
45
46
47
# File 'lib/moo/model/pack.rb', line 41

def fill_side_nums
  counter = 1
  @sides.reject {|s| s.side_num.is_a? Numeric}.each do |s|
    s.side_num = counter
    counter += 1
  end
end

#to_hashObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moo/model/pack.rb', line 28

def to_hash
  hash = {
    numCards: num_cards,
    productCode: product_code,
    productVersion: product_version,
    sides: sides.map {|s| s.to_hash }
  }

  hash[:imageBasket] = image_basket.to_hash unless image_basket.nil?

  hash
end

#to_jsonObject



24
25
26
# File 'lib/moo/model/pack.rb', line 24

def to_json
  to_hash.to_json
end