Class: ContactPoint::AddressBookBuilder
- Inherits:
-
Object
- Object
- ContactPoint::AddressBookBuilder
- Defined in:
- app/services/contact_point/address_book_builder.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#party ⇒ Object
readonly
Returns the value of attribute party.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#skip_organizations ⇒ Object
readonly
Returns the value of attribute skip_organizations.
-
#skip_persons ⇒ Object
readonly
Returns the value of attribute skip_persons.
Class Method Summary collapse
Instance Method Summary collapse
- #contact_options_flat ⇒ Object
- #contact_options_grouped ⇒ Object
- #current_party_options ⇒ Object
-
#initialize(options = {}) ⇒ AddressBookBuilder
constructor
A new instance of AddressBookBuilder.
- #options_for_select ⇒ Object
- #organization_options ⇒ Object
- #resource_options ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AddressBookBuilder
Returns a new instance of AddressBookBuilder.
9 10 11 12 13 14 15 16 |
# File 'app/services/contact_point/address_book_builder.rb', line 9 def initialize(={}) @party = [:party] @resource = [:resource] @organization = extract_organization @skip_persons = [:skip_persons] @skip_organizations = [:skip_organizations] @formatter = [:group_results] ? :contact_options_grouped : :contact_options_flat end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def formatter @formatter end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def organization @organization end |
#party ⇒ Object (readonly)
Returns the value of attribute party.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def party @party end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def resource @resource end |
#skip_organizations ⇒ Object (readonly)
Returns the value of attribute skip_organizations.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def skip_organizations @skip_organizations end |
#skip_persons ⇒ Object (readonly)
Returns the value of attribute skip_persons.
3 4 5 |
# File 'app/services/contact_point/address_book_builder.rb', line 3 def skip_persons @skip_persons end |
Class Method Details
.options_for_select(options = {}) ⇒ Object
5 6 7 |
# File 'app/services/contact_point/address_book_builder.rb', line 5 def self.( = {}) new(). end |
Instance Method Details
#contact_options_flat ⇒ Object
37 38 39 40 41 42 |
# File 'app/services/contact_point/address_book_builder.rb', line 37 def results = [] results += results += results.compact.uniq.sort end |
#contact_options_grouped ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/contact_point/address_book_builder.rb', line 25 def results = {} results[resource.to_s] = if organization results[organization.full_name] = elsif party # this is to handle contacts not linked to a customer (e.g opportunity participants) results[party.full_name] = end results.reject{|k,v| v.blank?} end |
#current_party_options ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/services/contact_point/address_book_builder.rb', line 60 def return [] unless party if (party.try(:is_person?) && !skip_persons) || (party.try(:is_organization?) && !skip_organizations) return [[party.name, party.id]] else return [] end end |
#options_for_select ⇒ Object
18 19 20 21 22 23 |
# File 'app/services/contact_point/address_book_builder.rb', line 18 def # Return empty array if neither party nor resource is available return [] unless @party || @resource send(formatter) end |
#organization_options ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/contact_point/address_book_builder.rb', line 48 def return [] unless organization @organization_options ||= begin opts = [] opts = [[organization.name, organization.id]] unless skip_organizations if organization.respond_to?(:contacts) && !skip_persons opts += organization.contacts.active.where.not(full_name: nil).pluck(:full_name, :id) end opts.compact.uniq.sort_by(&:first) end end |
#resource_options ⇒ Object
44 45 46 |
# File 'app/services/contact_point/address_book_builder.rb', line 44 def @resource_options ||= (resource.try(:participants_options_for_select) || []).compact.uniq.sort end |