module Quandl::Client::Base::Search
Public Instance Methods
attributes_with_scopes()
click to toggle source
# File lib/quandl/client/base/search.rb, line 42 def attributes_with_scopes attributes.merge(scope_attributes) end
each_in_page(options={}, &block)
click to toggle source
# File lib/quandl/client/base/search.rb, line 46 def each_in_page(options={}, &block) # count options[:count] ||= 0 options[:limit] ||= attributes[:limit] # fetch records records = all # pass each record upstream records.each do |r| # is a limit set? return if options[:limit].present? && options[:count] > options[:limit] # call block block.call( r ) # increase counter options[:count] += 1 end # blank array indidcates last page return if records.blank? || records.count < records.try(:metadata).try(:[], :per_page).to_i # next page scope_attributes[:page] = 1 if scope_attributes[:page].blank? scope_attributes[:page] = scope_attributes[:page].to_i + 1 # call recursively until we reach the end each_in_page(options, &block) end
fetch()
click to toggle source
# File lib/quandl/client/base/search.rb, line 32 def fetch find(attributes_with_scopes[:id]) end
fetch_once()
click to toggle source
# File lib/quandl/client/base/search.rb, line 28 def fetch_once @fetch_once ||= fetch end
find(id)
click to toggle source
# File lib/quandl/client/base/search.rb, line 36 def find(id) result = self.class.parent.where( attributes_with_scopes ).find(id) result = self.class.parent.new(id: id) if result.nil? result end