Class: Crunchbase::CBEntity

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

Constant Summary collapse

RELATIONSHIPS =
%w[ Crunchbase::Ipo Crunchbase::Product Crunchbase::SubOrganization  Crunchbase::FundingRound Crunchbase::Founder Crunchbase::Customer Crunchbase::Competitor Crunchbase::Acquisition Crunchbase::Degree Crunchbase::PrimaryAffiliation Crunchbase::Experience, Crunchbase::FoundedCompany Crunchbase::Video Crunchbase::PrimaryLocation Crunchbase::AdvisorAt Crunchbase::OrganizationInvestor ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.array_from_list(list) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/crunchbase/cb_entity.rb', line 52

def self.array_from_list(list)
  return [] if list.nil?

  list['items'].map do |l|
    self.new l if l.kind_of?(Hash)
  end.compact
end


33
34
35
36
37
# File 'lib/crunchbase/cb_entity.rb', line 33

def self.category_lists_by_permalink(permalink, classify_name, options={})
  options[:model_name]  = (RELATIONSHIPS.include?(self.name) ? Relationship : self)

  return API.lists_for_category(classify_name, permalink, self::RESOURCE_LIST, options)
end

.get(permalink) ⇒ Object

Factory method to return an instance from a permalink



9
10
11
# File 'lib/crunchbase/cb_entity.rb', line 9

def self.get(permalink)
  return self.new( API.single_entity(permalink, self::RESOURCE_NAME) )
end

.list(page = nil) ⇒ Object



46
47
48
49
50
# File 'lib/crunchbase/cb_entity.rb', line 46

def self.list(page=nil)
  options = { page: page, model_name: self }

  return API.list( options, self::RESOURCE_LIST )
end


21
22
23
24
25
# File 'lib/crunchbase/cb_entity.rb', line 21

def self.lists_for_permalink(permalink, options={})
  options[:model_name] = (RELATIONSHIPS.include?(self.name) ? Relationship : self)
  
  return API.lists_for_permalink(permalink, self::RESOURCE_LIST, options)
end


27
28
29
30
31
# File 'lib/crunchbase/cb_entity.rb', line 27

def self.lists_for_person_permalink(permalink, options={})
  options[:model_name] = (RELATIONSHIPS.include?(self.name) ? Relationship : self)
  
  return API.lists_for_person_permalink(permalink, self::RESOURCE_LIST, options)
end

.parsing_from_list(list) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/crunchbase/cb_entity.rb', line 60

def self.parsing_from_list(list)
  return [] if list.nil?
  
  list.map do |l|
    self.new l if l.kind_of?(Hash)
  end.compact
end

.search(options) ⇒ Object

Finds an entity by its name. Uses two HTTP requests; one to find the permalink, and another to request the actual entity.



15
16
17
18
19
# File 'lib/crunchbase/cb_entity.rb', line 15

def self.search(options)
  return [] unless self == Crunchbase::Organization

  return Search.new options, API.search( options, self::RESOURCE_LIST ), SearchResult
end

.total_items_from_list(list) ⇒ Object



68
69
70
71
72
# File 'lib/crunchbase/cb_entity.rb', line 68

def self.total_items_from_list(list)
  return 0 if list.nil?
  
  list['paging']['total_items']
end

Instance Method Details

#fetchObject



39
40
41
42
43
44
# File 'lib/crunchbase/cb_entity.rb', line 39

def fetch
  fetch_object = get_fetch_object
  return [] if fetch_object.empty?

  return fetch_object[0].new API.fetch(self.permalink, fetch_object[1])
end