Class: Crunchbase::Model::Entity

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ 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_nameObject (readonly)

Returns the value of attribute type_name.



6
7
8
# File 'lib/crunchbase/model/entity.rb', line 6

def type_name
  @type_name
end

#uuidObject (readonly)

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



67
68
69
70
71
72
73
# File 'lib/crunchbase/model/entity.rb', line 67

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

.funding_rounds_lists(permalink, options = {}) ⇒ Object



54
55
56
57
58
# File 'lib/crunchbase/model/entity.rb', line 54

def self.funding_rounds_lists(permalink, options={})
  options = options.merge({ model_name: self })

  return Crunchbase::API.funding_rounds_lists(permalink, self::RESOURCE_LIST.gsub('_', '-'), options)
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



75
76
77
78
79
80
81
# File 'lib/crunchbase/model/entity.rb', line 75

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



83
84
85
86
87
# File 'lib/crunchbase/model/entity.rb', line 83

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

Instance Method Details

#fetchObject



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

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