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

#convert_date!, #date_keys, #fetch, #instance_multi_relationship_objects, #instance_relationships_object, #instance_timestamps, #one_to_many, #one_to_one, #parse_hash_items, #property_keys, #relationship_lists, #set_relationships_object, #set_variables, #setup_relationships_data!, #special_relationship, #verify_item?

Methods included from Request::Client

#api, #array_from_list, #funding_rounds_lists, #get, #kclass_name, #list, #organization_lists, #parsing_from_list, #person_lists, #total_items_from_list

Constructor Details

#initialize(query, json, kclass) ⇒ Search

Returns a new instance of Search.



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

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

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

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



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

def current_page
  @current_page
end

#next_page_urlObject (readonly)

Returns the value of attribute next_page_url.



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

def next_page_url
  @next_page_url
end

#pagesObject (readonly)

Returns the value of attribute pages.



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

def pages
  @pages
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#prev_page_urlObject (readonly)

Returns the value of attribute prev_page_url.



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

def prev_page_url
  @prev_page_url
end

#resultsObject (readonly) Also known as: items

Returns the value of attribute results.



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

def results
  @results
end

#sort_orderObject (readonly)

Returns the value of attribute sort_order.



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

def sort_order
  @sort_order
end

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

Returns the value of attribute total_items.



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

def total_items
  @total_items
end

Class Method Details

.get(_permalink) ⇒ Object

Factory method to return an instance from a permalink



48
49
50
# File 'lib/crunchbase/model/search.rb', line 48

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.



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

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

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

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

Instance Method Details

#populate_results(json, kclass) ⇒ Object



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

def populate_results(json, kclass)
  @results = []
  @results = json['items'].map { |r| kclass.new(r) } unless json['items'].nil?

  @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