Sha256: b2c74093e40b1e4f9168c488eab04f0ba48f8fff4cfde1292302a36229b02b6b
Contents?: true
Size: 1.5 KB
Versions: 12
Compression:
Stored size: 1.5 KB
Contents
class Quandl::Client::Dataset::Data < Quandl::Client::Base @_her_resource_path = "datasets/:id/data" has_scope_composer scope.class_eval do delegate *Quandl::Client::Dataset::Data.forwardable_scope_methods, :to_h, to: :to_table, allow_nil: true delegate *Quandl::Data.forwardable_methods, to: :to_table, allow_nil: true end scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order, :transform, :collapse, :exclude_headers] scope :trim_start, ->(date){ date = parse_date(date); where( trim_start: date ) if date } scope :trim_end, ->(date){ date = parse_date(date); where( trim_end: date ) if date } scope_helper :parse_date, ->( value ){ begin date = Date.jd(value.to_i) if value.kind_of?(String) && value.numeric? date = Date.jd(value) if value.is_a?(Integer) date = Date.parse(value) if value.is_a?(String) && value =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/ date = value if value.is_a?(Date) date = value.to_date if value.respond_to?(:to_date) date.to_s rescue nil end } scope_helper :to_table, -> { fetch_once.data } attributes :id, :limit, :collapse, :transformation, :trim_start, :trim_end, :rows, :row, :frequency, :data, :from_date, :to_date def data read_data end def data=(value) write_data(value) end protected def read_data Quandl::Data.new( read_attribute(:data) ) end def write_data(value ) write_attribute(:data, Quandl::Data.new(value).to_csv ) end end
Version data entries
12 entries across 12 versions & 1 rubygems