Class: CustomerTopic::MatrixBuilder
- Inherits:
-
Object
- Object
- CustomerTopic::MatrixBuilder
- Defined in:
- app/services/customer_topic/matrix_builder.rb
Overview
This class is responsible for loading or initializing party topics
for a customer and its associated parties allowing an optional
category filter and sort order preferences
Instance Attribute Summary collapse
-
#category_id ⇒ Object
readonly
Returns the value of attribute category_id.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parties ⇒ Object
readonly
Returns the value of attribute parties.
Class Method Summary collapse
Instance Method Summary collapse
- #build_party_topics ⇒ Object
-
#initialize(customer, category_id = nil, party_ids_ordered = [], options = {}) ⇒ MatrixBuilder
constructor
A new instance of MatrixBuilder.
Constructor Details
#initialize(customer, category_id = nil, party_ids_ordered = [], options = {}) ⇒ MatrixBuilder
Returns a new instance of MatrixBuilder.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/customer_topic/matrix_builder.rb', line 7 def initialize(customer, category_id = nil, party_ids_ordered=[], = {}) @options = @logger = [:logger] || Rails.logger logger.debug "CustomerTopic::MatrixBuilder starting initialization" @customer = customer @category_id = category_id if party_ids_ordered.present? party_ids_ordered = party_ids_ordered.map(&:to_i) #This ruby trick preserves the original order of the array. @parties = Party.find(party_ids_ordered).index_by(&:id).slice(*party_ids_ordered).values else @parties = self.class.customer_and_contacts(@customer) end @party_ids_ordered = party_ids_ordered || @parties.map(&:id) load_topics prefetch_party_topics logger.debug "CustomerTopic::MatrixBuilder Initialization complete" end |
Instance Attribute Details
#category_id ⇒ Object (readonly)
Returns the value of attribute category_id.
5 6 7 |
# File 'app/services/customer_topic/matrix_builder.rb', line 5 def category_id @category_id end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
5 6 7 |
# File 'app/services/customer_topic/matrix_builder.rb', line 5 def customer @customer end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'app/services/customer_topic/matrix_builder.rb', line 5 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'app/services/customer_topic/matrix_builder.rb', line 5 def @options end |
#parties ⇒ Object (readonly)
Returns the value of attribute parties.
5 6 7 |
# File 'app/services/customer_topic/matrix_builder.rb', line 5 def parties @parties end |
Class Method Details
.customer_and_contacts(customer, contact_limit: 10) ⇒ Object
26 27 28 |
# File 'app/services/customer_topic/matrix_builder.rb', line 26 def self.customer_and_contacts(customer, contact_limit: 10) [customer] + customer.contacts.active.order(:full_name).limit(contact_limit) end |
Instance Method Details
#build_party_topics ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/customer_topic/matrix_builder.rb', line 31 def build_party_topics #Now we will initialize a hash of party topics, key is the party_id, and since rails has ordered hash we can ensure #they will load up in the same order when iterated over #Retrieve a select list of party topics #multi level hash initializer @party_topics = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) } @parties.each do |party| logger.debug "Building Party Topics for #{party.id} -> #{party.full_name}" build_party_topics_for_party party end @party_topics end |