Class: BBMB::Model::Customer
- Inherits:
-
Object
- Object
- BBMB::Model::Customer
- 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
-
#address1 ⇒ Object
Returns the value of attribute address1.
-
#address2 ⇒ Object
Returns the value of attribute address2.
-
#address3 ⇒ Object
Returns the value of attribute address3.
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
-
#canton ⇒ Object
Returns the value of attribute canton.
-
#city ⇒ Object
Returns the value of attribute city.
-
#customer_id ⇒ Object
Returns the value of attribute customer_id.
-
#drtitle ⇒ Object
Returns the value of attribute drtitle.
-
#ean13 ⇒ Object
Returns the value of attribute ean13.
-
#email ⇒ Object
Returns the value of attribute email.
-
#fax ⇒ Object
Returns the value of attribute fax.
-
#firstname ⇒ Object
Returns the value of attribute firstname.
-
#language ⇒ Object
Returns the value of attribute language.
-
#lastname ⇒ Object
Returns the value of attribute lastname.
-
#order_confirmation ⇒ Object
Returns the value of attribute order_confirmation.
-
#organisation ⇒ Object
Returns the value of attribute organisation.
-
#phone_business ⇒ Object
Returns the value of attribute phone_business.
-
#phone_mobile ⇒ Object
Returns the value of attribute phone_mobile.
-
#phone_private ⇒ Object
Returns the value of attribute phone_private.
-
#plz ⇒ Object
Returns the value of attribute plz.
-
#quotas ⇒ Object
readonly
Returns the value of attribute quotas.
-
#status ⇒ Object
Returns the value of attribute status.
-
#terms_last_accepted ⇒ Object
Returns the value of attribute terms_last_accepted.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #__old_commit_order__ ⇒ Object
- #__old_current_order__ ⇒ Object
- #__old_favorites__ ⇒ Object
- #__old_inject_order__ ⇒ Object
- #add_quota(quota) ⇒ Object
- #address_lines ⇒ Object
- #commit_order!(*args) ⇒ Object
- #current_order ⇒ Object
- #favorites ⇒ Object
-
#initialize(customer_id, email = nil) ⇒ Customer
constructor
A new instance of Customer.
- #inject_order(*args) ⇒ Object
- #order(commit_id) ⇒ Object
- #orders ⇒ Object
- #protect!(key) ⇒ Object
- #protects?(key) ⇒ Boolean
- #quota(article_id) ⇒ Object
- #turnover ⇒ Object
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
#address1 ⇒ Object
Returns the value of attribute address1.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def address1 @address1 end |
#address2 ⇒ Object
Returns the value of attribute address2.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def address2 @address2 end |
#address3 ⇒ Object
Returns the value of attribute address3.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def address3 @address3 end |
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
10 11 12 |
# File 'lib/bbmb/model/customer.rb', line 10 def archive @archive end |
#canton ⇒ Object
Returns the value of attribute canton.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def canton @canton end |
#city ⇒ Object
Returns the value of attribute city.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def city @city end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
10 11 12 |
# File 'lib/bbmb/model/customer.rb', line 10 def customer_id @customer_id end |
#drtitle ⇒ Object
Returns the value of attribute drtitle.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def drtitle @drtitle end |
#ean13 ⇒ Object
Returns the value of attribute ean13.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def ean13 @ean13 end |
#email ⇒ Object
Returns the value of attribute email.
10 11 12 |
# File 'lib/bbmb/model/customer.rb', line 10 def email @email end |
#fax ⇒ Object
Returns the value of attribute fax.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def fax @fax end |
#firstname ⇒ Object
Returns the value of attribute firstname.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def firstname @firstname end |
#language ⇒ Object
Returns the value of attribute language.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def language @language end |
#lastname ⇒ Object
Returns the value of attribute lastname.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def lastname @lastname end |
#order_confirmation ⇒ Object
Returns the value of attribute order_confirmation.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def order_confirmation @order_confirmation end |
#organisation ⇒ Object
Returns the value of attribute organisation.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def organisation @organisation end |
#phone_business ⇒ Object
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_mobile ⇒ Object
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_private ⇒ Object
Returns the value of attribute phone_private.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def phone_private @phone_private end |
#plz ⇒ Object
Returns the value of attribute plz.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def plz @plz end |
#quotas ⇒ Object (readonly)
Returns the value of attribute quotas.
10 11 12 |
# File 'lib/bbmb/model/customer.rb', line 10 def quotas @quotas end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/bbmb/model/customer.rb', line 11 def status @status end |
#terms_last_accepted ⇒ Object
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 |
#title ⇒ Object
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_lines ⇒ Object
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_order ⇒ Object
47 48 49 |
# File 'lib/bbmb/model/customer.rb', line 47 def current_order @current_order ||= Order.new(self) end |
#favorites ⇒ Object
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 |
#orders ⇒ Object
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 |
#turnover ⇒ Object
91 92 93 |
# File 'lib/bbmb/model/customer.rb', line 91 def turnover orders.inject(0) { |memo, order| order.total + memo } end |