Class: Crunchbase::Model::Search
- Includes:
- Enumerable
- Defined in:
- lib/crunchbase/model/search.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#next_page_url ⇒ Object
readonly
Returns the value of attribute next_page_url.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#prev_page_url ⇒ Object
readonly
Returns the value of attribute prev_page_url.
-
#results ⇒ Object
(also: #items)
readonly
Returns the value of attribute results.
-
#sort_order ⇒ Object
readonly
Returns the value of attribute sort_order.
-
#total_items ⇒ Object
(also: #length, #size)
readonly
Returns the value of attribute total_items.
Attributes inherited from Entity
Class Method Summary collapse
-
.get(permalink) ⇒ Object
Factory method to return an instance from a permalink.
-
.search(options, resource_list) ⇒ Object
Finds an entity by its name.
Instance Method Summary collapse
-
#initialize(query, json, _model) ⇒ Search
constructor
A new instance of Search.
- #populate_results(json, _model) ⇒ Object
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_page ⇒ Object (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_url ⇒ Object (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 |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
7 8 9 |
# File 'lib/crunchbase/model/search.rb', line 7 def pages @pages end |
#per_page ⇒ Object (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_url ⇒ Object (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 |
#results ⇒ Object (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_order ⇒ Object (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_items ⇒ Object (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(, resource_list) model_name = get_model_name(resource_list) raise 'Unknown type error!' if model_name.nil? return Search.new , Crunchbase::API.search( , 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 |