Class: Crunchbase::EntityListItem

Inherits:
Object
  • Object
show all
Defined in:
lib/crunchbase/entity_list_item.rb

Direct Known Subclasses

SearchResult

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#namespaceObject (readonly)

Returns the value of attribute namespace.



4
5
6
# File 'lib/crunchbase/entity_list_item.rb', line 4

def namespace
  @namespace
end

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_nameObject

Raises:



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_nameObject

Raises:



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

#nameObject

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