Class: ODDB::Migel::Product

Inherits:
Object show all
Includes:
FeedbackObserver, SimpleLanguage
Defined in:
src/model/migel/product.rb

Constant Summary

ODBA_SERIALIZABLE =
['@descriptions']

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from FeedbackObserver

#add_feedback, #feedback, #remove_feedback

Methods included from SimpleLanguage

#description, #descriptions, #has_description?, #match, #method_missing, #respond_to?, #to_s, #update_values

Methods included from PersistenceMethods

#data_origin, #data_origins, #diff, #init, #nil_if_empty, #parent, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (Product) initialize(code)

A new instance of Product



19
20
21
22
23
24
# File 'src/model/migel/product.rb', line 19

def initialize(code)
  @code = code
  @accessories = []
  @products = []
  @feedbacks = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ODDB::SimpleLanguage

Instance Attribute Details

- (Object) accessories (readonly)

Returns the value of attribute accessories



15
16
17
# File 'src/model/migel/product.rb', line 15

def accessories
  @accessories
end

- (Object) code (readonly) Also known as: pointer_descr

Returns the value of attribute code



15
16
17
# File 'src/model/migel/product.rb', line 15

def code
  @code
end

- (Object) date

Returns the value of attribute date



16
17
18
# File 'src/model/migel/product.rb', line 16

def date
  @date
end

- (Object) limitation

Returns the value of attribute limitation



16
17
18
# File 'src/model/migel/product.rb', line 16

def limitation
  @limitation
end

- (Object) limitation_text

Returns the value of attribute limitation_text



16
17
18
# File 'src/model/migel/product.rb', line 16

def limitation_text
  @limitation_text
end

- (Object) price

Returns the value of attribute price



16
17
18
# File 'src/model/migel/product.rb', line 16

def price
  @price
end

- (Object) product_text (readonly)

Returns the value of attribute product_text



15
16
17
# File 'src/model/migel/product.rb', line 15

def product_text
  @product_text
end

- (Object) products (readonly)

Returns the value of attribute products



15
16
17
# File 'src/model/migel/product.rb', line 15

def products
  @products
end

- (Object) qty

Returns the value of attribute qty



16
17
18
# File 'src/model/migel/product.rb', line 16

def qty
  @qty
end

- (Object) subgroup

Returns the value of attribute subgroup



16
17
18
# File 'src/model/migel/product.rb', line 16

def subgroup
  @subgroup
end

- (Object) type

Returns the value of attribute type



16
17
18
# File 'src/model/migel/product.rb', line 16

def type
  @type
end

- (Object) unit

Returns the value of attribute unit



16
17
18
# File 'src/model/migel/product.rb', line 16

def unit
  @unit
end

Instance Method Details

- (Object) accessory_code



25
26
27
# File 'src/model/migel/product.rb', line 25

def accessory_code
  @code.split('.', 2).last
end

- (Object) add_accessory(acc)



28
29
30
31
32
# File 'src/model/migel/product.rb', line 28

def add_accessory(acc)
  @accessories.push(acc)
  @accessories.odba_isolated_store
  acc
end

- (Object) add_product(prod)



33
34
35
36
37
38
39
40
41
42
43
44
# File 'src/model/migel/product.rb', line 33

def add_product(prod)
  if(prod != nil)
    unless(@products.include?(prod))
      if(prod)
        prod.add_accessory(self)
      end
      products.push(prod)
      @products.odba_store
    end
  end
  prod
end

- (Object) adjust_types(hash, app = nil)



45
46
47
48
49
50
51
52
53
# File 'src/model/migel/product.rb', line 45

def adjust_types(hash, app=nil)
  hash = hash.dup
  hash.each { |key, value|
    if(value.is_a?(Persistence::Pointer))
      hash[key] = value.resolve(app)
    end
  }
  hash
end

- (Object) checkout



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'src/model/migel/product.rb', line 54

def checkout
  @limitation_text.odba_delete unless(@limitation_text.nil?)
  @product_text.odba_delete unless(@product_text.nil?)
  @unit.odba_delete unless(@unit.nil?)
  @accessories.dup.each { |acc|
    acc.remove_product(self)
  }
  @accessories.odba_delete
  @products.each { |prd|
    prd.remove_accessory(self)
  }
  @products.odba_delete
  if(@feedbacks)
    @feedbacks.dup.each { |fb| fb.item = nil; fb.odba_store }
    @feedbacks.odba_delete
  end
end

- (Object) create_limitation_text



71
72
73
# File 'src/model/migel/product.rb', line 71

def create_limitation_text
  @limitation_text = LimitationText.new
end

- (Object) create_product_text



74
75
76
# File 'src/model/migel/product.rb', line 74

def create_product_text
  @product_text = Text::Document.new
end

- (Object) create_unit



77
78
79
# File 'src/model/migel/product.rb', line 77

def create_unit
  @unit = Text::Document.new
end

- (Object) delete_limitation_text



80
81
82
83
84
85
86
# File 'src/model/migel/product.rb', line 80

def delete_limitation_text
  if(lt = @limitation_text)
    @limitation_text = nil
    lt.odba_delete
    lt
  end
end

- (Object) delete_product_text



87
88
89
90
91
92
93
# File 'src/model/migel/product.rb', line 87

def delete_product_text
  if(pt = @product_text)
    @product_text = nil
    pt.odba_delete
    pt
  end
end

- (Object) delete_unit



94
95
96
97
98
99
100
# File 'src/model/migel/product.rb', line 94

def delete_unit
  if(ut = @unit)
    @unit = nil
    ut.odba_delete
    ut
  end
end

- (Object) group



101
102
103
# File 'src/model/migel/product.rb', line 101

def group
  @subgroup.group
end

- (Object) localized_name(language)



104
105
106
107
108
# File 'src/model/migel/product.rb', line 104

def localized_name(language)
  [ @product_text, self ].compact.collect { |part|
    part.send(language)
  }.join(': ').gsub("\n", ' ')
end

- (Object) migel_code



109
110
111
# File 'src/model/migel/product.rb', line 109

def migel_code
  [ @subgroup.migel_code, @code ].join('.')
end

- (Object) product_code



112
113
114
# File 'src/model/migel/product.rb', line 112

def product_code
  @code.split('.').first
end

- (Object) remove_accessory(acc)



115
116
117
118
119
120
# File 'src/model/migel/product.rb', line 115

def remove_accessory(acc)
  if(@accessories.delete(acc))
    @accessories.odba_isolated_store
    acc
  end
end

- (Object) remove_product(prod)



121
122
123
# File 'src/model/migel/product.rb', line 121

def remove_product(prod)
  prod.remove_accessory(self)
end

- (Object) search_terms(lang = :de)



124
125
126
127
128
129
130
131
# File 'src/model/migel/product.rb', line 124

def search_terms(lang = :de)
  terms = [ migel_code, ]
  [ group, group.limitation_text, @subgroup, @subgroup.limitation_text,
    @product_text, self, @limitation_text ].compact.each { |item|
    terms.push(item.send(lang))
  }
  ODDB.search_terms(terms)
end

- (Object) search_text(lang = :de)



132
133
134
# File 'src/model/migel/product.rb', line 132

def search_text(lang = :de)
  search_terms(lang).join(' ').downcase
end