Class: Crunchbase::Search
- Inherits:
-
Object
- Object
- Crunchbase::Search
- Includes:
- Enumerable
- Defined in:
- lib/crunchbase/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.
Class Method Summary collapse
-
.find(query) ⇒ Object
Performs a Crunchbase search for query.
- .search(query, t = 'organizations') ⇒ Object
Instance Method Summary collapse
-
#initialize(query, json, _model) ⇒ Search
constructor
A new instance of Search.
- #populate_results(json, _model) ⇒ Object
Constructor Details
#initialize(query, json, _model) ⇒ Search
Returns a new instance of Search.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/crunchbase/search.rb', line 25 def initialize(query, json, _model) @query = query @results = [] @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'] populate_results(json, _model) end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
7 8 9 |
# File 'lib/crunchbase/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/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/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/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/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/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/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/search.rb', line 7 def total_items @total_items end |
Class Method Details
.find(query) ⇒ Object
Performs a Crunchbase search for query.
15 16 17 |
# File 'lib/crunchbase/search.rb', line 15 def self.find(query) search(query) end |
.search(query, t = 'organizations') ⇒ Object
19 20 21 22 23 |
# File 'lib/crunchbase/search.rb', line 19 def self.search(query, t='organizations') query = { name: query } if query.kind_of?(String) Search.new query, API.search(query, t), SearchResult end |
Instance Method Details
#populate_results(json, _model) ⇒ Object
40 41 42 |
# File 'lib/crunchbase/search.rb', line 40 def populate_results(json, _model) @results = json["items"].map{|r| _model.new(r)} end |