Sha256: a198d5355d6bad0a778db89b4e11ee37c24c55577e970b31acf65b4660b0a798

Contents?: true

Size: 1.21 KB

Versions: 17

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

module Crunchbase
  class Search
    include Enumerable
    
    attr_reader :total_items, :per_page, :pages, :current_page, 
                :prev_page_url, :next_page_url, :sort_order, :results

    alias :length :total_items
    alias :size   :total_items
    alias :items  :results

    # Performs a Crunchbase search for query.
    def self.find(query)
      search(query)
    end

    def self.search(query, t='organizations')
      query = { name: query } if query.kind_of?(String)

      Search.new query, API.search(query, t), SearchResult
    end

    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


    def populate_results(json, _model)
      @results = json["items"].map{|r| _model.new(r)}
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
crunchbase_v2-1.1.6 lib/crunchbase/search.rb
crunchbase_v2-1.1.5 lib/crunchbase/search.rb
crunchbase_v2-1.1.4 lib/crunchbase/search.rb
crunchbase_v2-1.1.3 lib/crunchbase/search.rb
crunchbase_v2-1.1.2 lib/crunchbase/search.rb
crunchbase_v2-1.1.1 lib/crunchbase/search.rb
crunchbase_v2-1.1.0 lib/crunchbase/search.rb
crunchbase_v2-1.0.0 lib/crunchbase/search.rb
crunchbase_v2-0.0.9 lib/crunchbase/search.rb
crunchbase_v2-0.0.8 lib/crunchbase/search.rb
crunchbase_v2-0.0.7 lib/crunchbase/search.rb
crunchbase_v2-0.0.6 lib/crunchbase/search.rb
crunchbase_v2-0.0.5 lib/crunchbase/search.rb
crunchbase_v2-0.0.4 lib/crunchbase/search.rb
crunchbase_v2-0.0.3 lib/crunchbase/search.rb
crunchbase_v2-0.0.2 lib/crunchbase/search.rb
crunchbase_v2-0.0.1 lib/crunchbase/search.rb