Class: TocDoc::Profile
- Defined in:
- lib/toc_doc/models/profile.rb,
lib/toc_doc/models/profile/organization.rb,
lib/toc_doc/models/profile/practitioner.rb
Overview
Represents a search profile result (practitioner or organization). Inherits dot-notation attribute access from +TocDoc::Resource+.
Use +Profile.build+ to obtain the correctly typed subclass instance.
Direct Known Subclasses
Defined Under Namespace
Classes: Organization, Practitioner
Constant Summary collapse
- PATH =
API path template for a full profile page (+sprintf+-style, requires +identifier+).
'/profiles/%<identifier>s.json'
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.build(attrs = {}) ⇒ Profile::Practitioner, Profile::Organization
Factory — returns a +Profile::Practitioner+ or +Profile::Organization+.
-
.find(identifier) ⇒ Profile::Practitioner, Profile::Organization
Fetches a full profile page by slug or numeric ID.
Instance Method Summary collapse
-
#id ⇒ Integer, ...
Returns the profile ID, falling back to the +value+ key used in autocomplete responses when +id+ is absent.
-
#load_full_profile! ⇒ self
Replaces this profile's attributes with those from the full profile page, making a network request only when the profile is currently partial.
-
#organization? ⇒ Boolean
True when this profile is an organization.
-
#practitioner? ⇒ Boolean
True when this profile is a practitioner.
-
#skills ⇒ Array<TocDoc::Resource>
Returns all skills across all practices as an array of Resource.
-
#skills_for(practice_id) ⇒ Array<TocDoc::Resource>
Returns skills for a single practice as an array of Resource.
Methods inherited from Resource
#==, #[], #[]=, #attribute_names, #initialize, #inspect, main_attrs, #method_missing, normalize_attrs, #to_h, #to_json
Constructor Details
This class inherits a constructor from TocDoc::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class TocDoc::Resource
Class Method Details
.build(attrs = {}) ⇒ Profile::Practitioner, Profile::Organization
Factory — returns a +Profile::Practitioner+ or +Profile::Organization+.
Resolves type via +owner_type+ first (autocomplete context), then falls back to the boolean flags present on profile-page responses.
36 37 38 39 40 41 42 43 44 |
# File 'lib/toc_doc/models/profile.rb', line 36 def build(attrs = {}) attrs = normalize_attrs(attrs) return find(attrs['value']) if attrs['force_full_profile'] build_from_autocomplete(attrs) || build_from_booking_info(attrs) || build_from_full_profile(attrs) end |
.find(identifier) ⇒ Profile::Practitioner, Profile::Organization
Fetches a full profile page by slug or numeric ID.
55 56 57 58 59 60 |
# File 'lib/toc_doc/models/profile.rb', line 55 def find(identifier) raise ArgumentError, 'identifier cannot be nil' if identifier.nil? data = TocDoc.client.get(format(PATH, identifier: identifier))['data'] build(profile_attrs(data)) end |
Instance Method Details
#id ⇒ Integer, ...
Returns the profile ID, falling back to the +value+ key used in autocomplete responses when +id+ is absent.
173 174 175 |
# File 'lib/toc_doc/models/profile.rb', line 173 def id self['id'] || self['value'] end |
#load_full_profile! ⇒ self
Replaces this profile's attributes with those from the full profile page, making a network request only when the profile is currently partial. Returns +self+ for chaining.
182 183 184 185 186 187 188 189 |
# File 'lib/toc_doc/models/profile.rb', line 182 def load_full_profile! return unless partial full_profile = self.class.find(id) @attrs = full_profile.instance_variable_get(:@attrs) @partial = false self end |
#organization? ⇒ Boolean
Returns true when this profile is an organization.
165 166 167 |
# File 'lib/toc_doc/models/profile.rb', line 165 def organization? is_a?(Organization) end |
#practitioner? ⇒ Boolean
Returns true when this profile is a practitioner.
157 158 159 |
# File 'lib/toc_doc/models/profile.rb', line 157 def practitioner? is_a?(Practitioner) end |
#skills ⇒ Array<TocDoc::Resource>
Returns all skills across all practices as an array of Resource.
136 137 138 139 |
# File 'lib/toc_doc/models/profile.rb', line 136 def skills hash = self['skills_by_practice'] || {} hash.values.flatten.map { |s| TocDoc::Resource.new(s) } end |
#skills_for(practice_id) ⇒ Array<TocDoc::Resource>
Returns skills for a single practice as an array of Resource.
148 149 150 151 |
# File 'lib/toc_doc/models/profile.rb', line 148 def skills_for(practice_id) hash = self['skills_by_practice'] || {} Array(hash[practice_id.to_s]).map { |s| TocDoc::Resource.new(s) } end |