Class: Crunchbase::Model::Entity
- Inherits:
-
Object
- Object
- Crunchbase::Model::Entity
show all
- Defined in:
- lib/crunchbase/model/entity.rb
Direct Known Subclasses
Acquisition, Address, Category, Degree, Error, FoundedCompany, Fund, FundingRound, Image, Investment, Investor, Ipo, Job, Location, New, Organization, OrganizationSummary, OwnedBy, Person, PersonSummary, Product, Search, SearchResult, Video, Website
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(json) ⇒ Entity
Returns a new instance of Entity.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/crunchbase/model/entity.rb', line 8
def initialize(json)
instance_variable_set("@type_name", json['type'] || nil)
instance_variable_set("@uuid", json['uuid'] || nil)
property_keys.each { |v|
instance_variable_set("@#{v}", json['properties'][v] || nil)
}
date_keys.each { |v|
instance_variable_set("@#{v}", json['properties'][v].nil? ? nil : Date.parse(json['properties'][v]))
}
%w[created_at updated_at].each { |v|
if json['properties'][v].kind_of?(String)
instance_variable_set( "@#{v}", begin Time.parse(json['properties'][v]) rescue nil end )
else
instance_variable_set( "@#{v}", begin Time.at(json['properties'][v]) rescue nil end )
end
}
end
|
Instance Attribute Details
#type_name ⇒ Object
Returns the value of attribute type_name.
6
7
8
|
# File 'lib/crunchbase/model/entity.rb', line 6
def type_name
@type_name
end
|
#uuid ⇒ Object
Returns the value of attribute uuid.
6
7
8
|
# File 'lib/crunchbase/model/entity.rb', line 6
def uuid
@uuid
end
|
Class Method Details
.array_from_list(list) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/crunchbase/model/entity.rb', line 61
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
|
.get(permalink) ⇒ Object
Factory method to return an instance from a permalink
30
31
32
33
34
|
# File 'lib/crunchbase/model/entity.rb', line 30
def self.get(permalink)
result = Crunchbase::API.single_entity(permalink, self::RESOURCE_NAME)
return self.new( result )
end
|
.list(page = nil) ⇒ Object
36
37
38
39
40
|
# File 'lib/crunchbase/model/entity.rb', line 36
def self.list(page=nil)
model_name = get_model_name(self::RESOURCE_LIST)
return Crunchbase::API.list( { page: page, model_name: model_name }, self::RESOURCE_LIST )
end
|
.organization_lists(permalink, options = {}) ⇒ Object
42
43
44
45
46
|
# File 'lib/crunchbase/model/entity.rb', line 42
def self.organization_lists(permalink, options={})
options = options.merge({ model_name: self })
return Crunchbase::API.organization_lists(permalink, self::RESOURCE_LIST, options)
end
|
.parsing_from_list(list) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/crunchbase/model/entity.rb', line 69
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
|
.person_lists(permalink, options = {}) ⇒ Object
48
49
50
51
52
|
# File 'lib/crunchbase/model/entity.rb', line 48
def self.person_lists(permalink, options={})
options = options.merge({ model_name: self })
return Crunchbase::API.person_lists(permalink, self::RESOURCE_LIST, options)
end
|
.total_items_from_list(list) ⇒ Object
77
78
79
80
81
|
# File 'lib/crunchbase/model/entity.rb', line 77
def self.total_items_from_list(list)
return 0 if list.nil?
list['paging']['total_items']
end
|
Instance Method Details
#fetch ⇒ Object
54
55
56
57
58
59
|
# File 'lib/crunchbase/model/entity.rb', line 54
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
|