Class: BBMB::Model::Customer

Inherits:
Object
  • Object
show all
Includes:
ODBA::Persistable
Defined in:
lib/bbmb/model/customer.rb,
lib/bbmb/persistence/odba/model/customer.rb

Constant Summary collapse

ODBA_PREFETCH =
true
ODBA_SERIALIZABLE =
['@protected']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer_id, email = nil) ⇒ Customer



15
16
17
18
19
20
21
22
# File 'lib/bbmb/model/customer.rb', line 15

def initialize(customer_id, email=nil)
  @archive = {}
  self.customer_id = customer_id if customer_id
  @email = email
  @favorites = Order.new(self)
  @protected = {}
  @quotas = []
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def address2
  @address2
end

#address3Object

Returns the value of attribute address3.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def address3
  @address3
end

#archiveObject (readonly)

Returns the value of attribute archive.



10
11
12
# File 'lib/bbmb/model/customer.rb', line 10

def archive
  @archive
end

#cantonObject

Returns the value of attribute canton.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def canton
  @canton
end

#cityObject

Returns the value of attribute city.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def city
  @city
end

#customer_idObject

Returns the value of attribute customer_id.



10
11
12
# File 'lib/bbmb/model/customer.rb', line 10

def customer_id
  @customer_id
end

#drtitleObject

Returns the value of attribute drtitle.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def drtitle
  @drtitle
end

#ean13Object

Returns the value of attribute ean13.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def ean13
  @ean13
end

#emailObject

Returns the value of attribute email.



10
11
12
# File 'lib/bbmb/model/customer.rb', line 10

def email
  @email
end

#faxObject

Returns the value of attribute fax.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def fax
  @fax
end

#firstnameObject

Returns the value of attribute firstname.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def firstname
  @firstname
end

#languageObject

Returns the value of attribute language.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def language
  @language
end

#lastnameObject

Returns the value of attribute lastname.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def lastname
  @lastname
end

#order_confirmationObject

Returns the value of attribute order_confirmation.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def order_confirmation
  @order_confirmation
end

#organisationObject

Returns the value of attribute organisation.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def organisation
  @organisation
end

#phone_businessObject

Returns the value of attribute phone_business.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def phone_business
  @phone_business
end

#phone_mobileObject

Returns the value of attribute phone_mobile.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def phone_mobile
  @phone_mobile
end

#phone_privateObject

Returns the value of attribute phone_private.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def phone_private
  @phone_private
end

#plzObject

Returns the value of attribute plz.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def plz
  @plz
end

#quotasObject (readonly)

Returns the value of attribute quotas.



10
11
12
# File 'lib/bbmb/model/customer.rb', line 10

def quotas
  @quotas
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def status
  @status
end

#terms_last_acceptedObject

Returns the value of attribute terms_last_accepted.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def terms_last_accepted
  @terms_last_accepted
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/bbmb/model/customer.rb', line 11

def title
  @title
end

Instance Method Details

#__old_commit_order__Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 23

def commit_order!(commit_time = Time.now)
  Thread.exclusive {
    id = @archive.keys.max.to_i.next
    order = current_order
    order.commit!(id, commit_time)
    @archive.store(id, order)
    @current_order = nil
    order
  }
end

#__old_current_order__Object



15
16
17
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 15

def current_order
  @current_order ||= Order.new(self)
end

#__old_favorites__Object



37
38
39
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 37

def favorites 
  @favorites ||= Order.new(self)
end

#__old_inject_order__Object



30
31
32
33
34
35
36
37
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 30

def inject_order(order, commit_time = Time.now)
  Thread.exclusive {
    id = @archive.keys.max.to_i.next
    order.commit!(id, commit_time)
    @archive.store(id, order)
    order
  }
end

#add_quota(quota) ⇒ Object



23
24
25
26
# File 'lib/bbmb/model/customer.rb', line 23

def add_quota(quota)
  @quotas.push(quota).uniq!
  quota
end

#address_linesObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/bbmb/model/customer.rb', line 27

def address_lines
  [
    @organisation,
    [@drtitle, @firstname, @lastname].compact.join(' '),
    @address1,
    @address2,
    @address3,
    [@plz, @city].compact.join(' '),
  ].compact
end

#commit_order!(*args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/bbmb/model/customer.rb', line 37

def commit_order!(commit_time = Time.now)
  Thread.exclusive {
    id = @archive.keys.max.to_i.next
    order = current_order
    order.commit!(id, commit_time)
    @archive.store(id, order)
    @current_order = nil
    order
  }
end

#current_orderObject



47
48
49
# File 'lib/bbmb/model/customer.rb', line 47

def current_order
  @current_order ||= Order.new(self)
end

#favoritesObject



68
69
70
# File 'lib/bbmb/model/customer.rb', line 68

def favorites 
  @favorites ||= Order.new(self)
end

#inject_order(*args) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/bbmb/model/customer.rb', line 71

def inject_order(order, commit_time = Time.now)
  Thread.exclusive {
    id = @archive.keys.max.to_i.next
    order.commit!(id, commit_time)
    @archive.store(id, order)
    order
  }
end

#order(commit_id) ⇒ Object



79
80
81
# File 'lib/bbmb/model/customer.rb', line 79

def order(commit_id)
  @archive[commit_id.to_i]
end

#ordersObject



82
83
84
# File 'lib/bbmb/model/customer.rb', line 82

def orders
  @archive.values
end

#protect!(key) ⇒ Object



85
86
87
# File 'lib/bbmb/model/customer.rb', line 85

def protect!(key)
  @protected.store(key, true)
end

#protects?(key) ⇒ Boolean



88
89
90
# File 'lib/bbmb/model/customer.rb', line 88

def protects?(key)
  @protected.fetch(key, false)
end

#quota(article_id) ⇒ Object



57
58
59
# File 'lib/bbmb/model/customer.rb', line 57

def quota(article_id)
  @quotas.find { |quota| quota.article_number == article_id }
end

#turnoverObject



91
92
93
# File 'lib/bbmb/model/customer.rb', line 91

def turnover
  orders.inject(0) { |memo, order| order.total + memo }
end