Class: Crunchbase::Model::Search

Inherits:
Entity
  • Object
show all
Includes:
Enumerable
Defined in:
lib/crunchbase/model/search.rb

Instance Attribute Summary collapse

Attributes inherited from Entity

#type_name, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

array_from_list, #fetch, funding_rounds_lists, list, organization_lists, parsing_from_list, person_lists, total_items_from_list

Constructor Details

#initialize(query, json, _model) ⇒ Search



13
14
15
16
17
18
19
20
# File 'lib/crunchbase/model/search.rb', line 13

def initialize(query, json, _model)
  @query            = query
  @results          = []
  @total_items      = 0
  @pages            = 0

  populate_results(json, _model) if json['error'].nil?
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def current_page
  @current_page
end

#next_page_urlObject (readonly)

Returns the value of attribute next_page_url.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def next_page_url
  @next_page_url
end

#pagesObject (readonly)

Returns the value of attribute pages.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def pages
  @pages
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def per_page
  @per_page
end

#prev_page_urlObject (readonly)

Returns the value of attribute prev_page_url.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def prev_page_url
  @prev_page_url
end

#resultsObject (readonly) Also known as: items

Returns the value of attribute results.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def results
  @results
end

#sort_orderObject (readonly)

Returns the value of attribute sort_order.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def sort_order
  @sort_order
end

#total_itemsObject (readonly) Also known as: length, size

Returns the value of attribute total_items.



7
8
9
# File 'lib/crunchbase/model/search.rb', line 7

def total_items
  @total_items
end

Class Method Details

.get(permalink) ⇒ Object

Factory method to return an instance from a permalink



46
47
48
# File 'lib/crunchbase/model/search.rb', line 46

def self.get(permalink)
  nil
end

.search(options, resource_list) ⇒ Object

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



37
38
39
40
41
42
43
# File 'lib/crunchbase/model/search.rb', line 37

def self.search(options, resource_list)
  model_name = get_model_name(resource_list)

  raise 'Unknown type error!' if model_name.nil?

  return Search.new options, Crunchbase::API.search( options, resource_list ), model_name
end

Instance Method Details

#populate_results(json, _model) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crunchbase/model/search.rb', line 23

def populate_results(json, _model)
  @results = json["items"].map{|r| _model.new(r)}
  
  @total_items      = json['paging']['total_items']
  @per_page         = json['paging']['items_per_page']
  @pages            = json['paging']['number_of_pages']
  @current_page     = json['paging']['current_page']
  @prev_page_url    = json['paging']['prev_page_url']
  @next_page_url    = json['paging']['next_page_url']
  @sort_order       = json['paging']['sort_order']
end