Class: Crunchbase::Search

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_pageObject (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_urlObject (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

#pagesObject (readonly)

Returns the value of attribute pages.



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

def pages
  @pages
end

#per_pageObject (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_urlObject (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

#resultsObject (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_orderObject (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_itemsObject (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