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
- MUTEX =
Mutex.new
- 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
-
#set_email_without_yus(email) ⇒ Object
This method is only for the importer!.
- #turnover ⇒ Object
Constructor Details
#initialize(customer_id, email = nil) ⇒ Customer
Returns a new instance of Customer.
17 18 19 20 21 22 23 24 |
# File 'lib/bbmb/model/customer.rb', line 17 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.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def address1 @address1 end |
#address2 ⇒ Object
Returns the value of attribute address2.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def address2 @address2 end |
#address3 ⇒ Object
Returns the value of attribute address3.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def address3 @address3 end |
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
12 13 14 |
# File 'lib/bbmb/model/customer.rb', line 12 def archive @archive end |
#canton ⇒ Object
Returns the value of attribute canton.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def canton @canton end |
#city ⇒ Object
Returns the value of attribute city.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def city @city end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
12 13 14 |
# File 'lib/bbmb/model/customer.rb', line 12 def customer_id @customer_id end |
#drtitle ⇒ Object
Returns the value of attribute drtitle.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def drtitle @drtitle end |
#ean13 ⇒ Object
Returns the value of attribute ean13.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def ean13 @ean13 end |
#email ⇒ Object
Returns the value of attribute email.
12 13 14 |
# File 'lib/bbmb/model/customer.rb', line 12 def email @email end |
#fax ⇒ Object
Returns the value of attribute fax.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def fax @fax end |
#firstname ⇒ Object
Returns the value of attribute firstname.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def firstname @firstname end |
#language ⇒ Object
Returns the value of attribute language.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def language @language end |
#lastname ⇒ Object
Returns the value of attribute lastname.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def lastname @lastname end |
#order_confirmation ⇒ Object
Returns the value of attribute order_confirmation.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def order_confirmation @order_confirmation end |
#organisation ⇒ Object
Returns the value of attribute organisation.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def organisation @organisation end |
#phone_business ⇒ Object
Returns the value of attribute phone_business.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def phone_business @phone_business end |
#phone_mobile ⇒ Object
Returns the value of attribute phone_mobile.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def phone_mobile @phone_mobile end |
#phone_private ⇒ Object
Returns the value of attribute phone_private.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def phone_private @phone_private end |
#plz ⇒ Object
Returns the value of attribute plz.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def plz @plz end |
#quotas ⇒ Object (readonly)
Returns the value of attribute quotas.
12 13 14 |
# File 'lib/bbmb/model/customer.rb', line 12 def quotas @quotas end |
#status ⇒ Object
Returns the value of attribute status.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def status @status end |
#terms_last_accepted ⇒ Object
Returns the value of attribute terms_last_accepted.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def terms_last_accepted @terms_last_accepted end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/bbmb/model/customer.rb', line 13 def title @title end |
Instance Method Details
#__old_commit_order__ ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 27 def commit_order!(commit_time = Time.now) MUTEX.synchronize { 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
41 42 43 |
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 41 def favorites @favorites ||= Order.new(self) end |
#__old_inject_order__ ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/bbmb/persistence/odba/model/customer.rb', line 34 def inject_order(order, commit_time = Time.now) MUTEX.synchronize { id = @archive.keys.max.to_i.next order.commit!(id, commit_time) @archive.store(id, order) order } end |
#add_quota(quota) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/bbmb/model/customer.rb', line 25 def add_quota(quota) unless @quotas.is_a?(Array) puts "customer #{customer_id}: Fixing quotas #{@quotas} -> []" @quotas = [] odba_store; end @quotas.push(quota).uniq! quota end |
#address_lines ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bbmb/model/customer.rb', line 34 def address_lines [ @organisation, [@drtitle, @firstname, @lastname].compact.join(' '), @address1, @address2, @address3, [@plz, @city].compact.join(' '), ].compact end |
#commit_order!(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bbmb/model/customer.rb', line 44 def commit_order!(commit_time = Time.now) MUTEX.synchronize { 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
54 55 56 |
# File 'lib/bbmb/model/customer.rb', line 54 def current_order @current_order ||= Order.new(self) end |
#favorites ⇒ Object
84 85 86 |
# File 'lib/bbmb/model/customer.rb', line 84 def favorites @favorites ||= Order.new(self) end |
#inject_order(*args) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/bbmb/model/customer.rb', line 87 def inject_order(order, commit_time = Time.now) MUTEX.synchronize { id = @archive.keys.max.to_i.next order.commit!(id, commit_time) @archive.store(id, order) order } end |
#order(commit_id) ⇒ Object
95 96 97 |
# File 'lib/bbmb/model/customer.rb', line 95 def order(commit_id) @archive[commit_id.to_i] end |
#orders ⇒ Object
98 99 100 |
# File 'lib/bbmb/model/customer.rb', line 98 def orders @archive.values end |
#protect!(key) ⇒ Object
101 102 103 |
# File 'lib/bbmb/model/customer.rb', line 101 def protect!(key) @protected.store(key, true) end |
#protects?(key) ⇒ Boolean
104 105 106 |
# File 'lib/bbmb/model/customer.rb', line 104 def protects?(key) @protected.fetch(key, false) end |
#quota(article_id) ⇒ Object
64 65 66 |
# File 'lib/bbmb/model/customer.rb', line 64 def quota(article_id) @quotas.compact.find { |quota| quota.article_number == article_id } end |
#set_email_without_yus(email) ⇒ Object
This method is only for the importer!
68 69 70 71 72 73 |
# File 'lib/bbmb/model/customer.rb', line 68 def set_email_without_yus(email) raise "Invalid email address: nil" unless email email = email.encode('UTF-8') return if @email.eql?(email) @email = email end |
#turnover ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bbmb/model/customer.rb', line 107 def turnover orders.inject(0) do |memo, order| begin order.total + memo rescue => error SBSM.info "turnover error for #{order.order_id} returning memo" memo end end end |