Class: Crunchbase::EntityListItem
- Inherits:
-
Object
- Object
- Crunchbase::EntityListItem
- Defined in:
- lib/crunchbase/entity_list_item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
Instance Method Summary collapse
-
#entity(force_reload = false) ⇒ Object
Returns the entity associated with the search result, loading from memory if previously fetched, unless
force_reloadis set to true. - #first_name ⇒ Object
-
#initialize(json) ⇒ EntityListItem
constructor
A new instance of EntityListItem.
- #last_name ⇒ Object
-
#name ⇒ Object
Returns concatenation of first and last names if person, otherwise returns name.
Constructor Details
#initialize(json) ⇒ EntityListItem
Returns a new instance of EntityListItem.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/crunchbase/entity_list_item.rb', line 6 def initialize(json) @namespace = json["namespace"] if @namespace == "person" @first_name = json["first_name"] @last_name = json["last_name"] else @name = json["name"] end @permalink = json["permalink"] end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/crunchbase/entity_list_item.rb', line 4 def namespace @namespace end |
#permalink ⇒ Object (readonly)
Returns the value of attribute permalink.
4 5 6 |
# File 'lib/crunchbase/entity_list_item.rb', line 4 def permalink @permalink end |
Instance Method Details
#entity(force_reload = false) ⇒ Object
Returns the entity associated with the search result, loading from memory if previously fetched, unless force_reload is set to true.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/crunchbase/entity_list_item.rb', line 41 def entity(force_reload=false) return @entity unless @entity.nil? || force_reload @entity = case @namespace when "company" Company.get(@permalink) when "financial-organization" FinancialOrganization.get(@permalink) when "person" Person.get(@permalink) when "product" Product.get(@permalink) when "service-provider" ServiceProvider.get(@permalink) end return @entity end |
#first_name ⇒ Object
17 18 19 20 |
# File 'lib/crunchbase/entity_list_item.rb', line 17 def first_name raise CrunchException, "Not available for this entity" unless namespace == "person" @first_name end |
#last_name ⇒ Object
22 23 24 25 |
# File 'lib/crunchbase/entity_list_item.rb', line 22 def last_name raise CrunchException, "Not available for this entity" unless namespace == "person" @last_name end |
#name ⇒ Object
Returns concatenation of first and last names if person, otherwise returns name. Thus, if you wanted to, for example, iterate over search results and output the name, you could do so without checking entity type first.
31 32 33 34 35 36 37 |
# File 'lib/crunchbase/entity_list_item.rb', line 31 def name if @namespace == "person" @first_name + " " + @last_name else @name end end |