module Quandl::Data::Operations

Public Instance Methods

clone() click to toggle source
# File lib/quandl/data/operations.rb, line 137
def clone
  self.class.new( _attributes: attributes.clone )
end
collapse(*args) click to toggle source
# File lib/quandl/data/operations.rb, line 118
def collapse(*args)
  return @collapse unless args.first.present?
  self.collapse = args.first
  self
end
collapse=(collapse) click to toggle source
# File lib/quandl/data/operations.rb, line 123
def collapse=(collapse)
  return false unless Quandl::Operation::Collapse.valid?(collapse)
  @collapse = collapse
  @frequency = collapse
  self.data_array = Quandl::Operation::Collapse.perform( data_array, collapse )
end
frequency() click to toggle source
# File lib/quandl/data/operations.rb, line 130
def frequency
  @frequency ||= Quandl::Babelfish.guess_frequency( data_array ).try(:to_sym)
end
frequency=(value) click to toggle source
# File lib/quandl/data/operations.rb, line 133
def frequency=(value)
  @frequency = value.to_sym if value.present?
end
limit(amount) click to toggle source
# File lib/quandl/data/operations.rb, line 159
def limit(amount)
  clone.limit!(amount)
end
limit!(amount) click to toggle source
# File lib/quandl/data/operations.rb, line 79
def limit!(amount)
  self.data_array = data_array[0..( amount.to_i - 1 )]; self
end
row(*args) click to toggle source
# File lib/quandl/data/operations.rb, line 99
def row(*args)
  return @row if args[0].nil?
  @row = args[0]
  self.data_array = [data_array[ args[0] ]]
  self
end
sort_ascending() click to toggle source
# File lib/quandl/data/operations.rb, line 162
def sort_ascending
  clone.sort_ascending!
end
sort_ascending!() click to toggle source
# File lib/quandl/data/operations.rb, line 87
def sort_ascending!
  self.data_array = Quandl::Operation::Sort.asc( data_array ); self
end
sort_descending() click to toggle source
# File lib/quandl/data/operations.rb, line 165
def sort_descending
  clone.sort_descending!
end
sort_descending!() click to toggle source
# File lib/quandl/data/operations.rb, line 91
def sort_descending!
  self.data_array = Quandl::Operation::Sort.desc( data_array ); self
end
sort_order(dir) click to toggle source
# File lib/quandl/data/operations.rb, line 83
def sort_order(dir)
  dir == :asc ? sort_ascending! : sort_descending!
end
to_csv() click to toggle source
# File lib/quandl/data/operations.rb, line 34
def to_csv
  return data_array.collect(&:to_csv).join if data_array?
  return pristine_data.collect(&:to_csv).join if pristine_data.respond_to?(:collect)
  return pristine_data if pristine_data.kind_of?(String)
  return ''
end
to_date() click to toggle source
# File lib/quandl/data/operations.rb, line 147
def to_date
  clone.to_date!
end
to_date!() click to toggle source
# File lib/quandl/data/operations.rb, line 49
def to_date!
  self.data_array = Quandl::Data::Format.to_date( data_array ); self
end
to_date_str() click to toggle source
# File lib/quandl/data/operations.rb, line 150
def to_date_str
  clone.to_date_str!
end
to_date_str!() click to toggle source
# File lib/quandl/data/operations.rb, line 53
def to_date_str!
  self.data_array = to_date!.collect{|r| r = r.dup; r[0] = r[0].to_s; r }; self
end
to_h() click to toggle source
# File lib/quandl/data/operations.rb, line 27
def to_h
  data_array.inject({}) do |memo, row|
    memo[row[0]] = row[1..-1]
    memo
  end
end
to_jd() click to toggle source
# File lib/quandl/data/operations.rb, line 144
def to_jd
  clone.to_jd!
end
to_jd!() click to toggle source
# File lib/quandl/data/operations.rb, line 45
def to_jd!
  self.data_array = Quandl::Data::Format.to_jd( data_array ); self
end
to_precision(value) click to toggle source
# File lib/quandl/data/operations.rb, line 141
def to_precision(value)
  clone.to_precision!(value)
end
to_precision!(value) click to toggle source
# File lib/quandl/data/operations.rb, line 95
def to_precision!(value)
  self.data_array = Quandl::Operation::Value.precision(data_array, value); self
end
to_table() click to toggle source
# File lib/quandl/data/operations.rb, line 41
def to_table
  self
end
transform(*args) click to toggle source
# File lib/quandl/data/operations.rb, line 106
def transform(*args)
  return @transform unless args.first.present?
  self.transform = args.first
  self
end
transform=(value) click to toggle source
# File lib/quandl/data/operations.rb, line 111
def transform=(value)
  return false unless Quandl::Operation::Transform.valid?(value)
  @transform = value
  self.data_array = Quandl::Operation::Transform.perform( data_array, value )
  self.data_array
end
trim_end(date) click to toggle source
# File lib/quandl/data/operations.rb, line 156
def trim_end(date)
  clone.trim_end!(date)
end
trim_end!(date) click to toggle source
# File lib/quandl/data/operations.rb, line 68
def trim_end!(date)
  # date format
  date = Quandl::Operation::QDate.parse(date)
  # reject rows with dates less than
  self.data_array = to_date!.sort_descending!.delete_if do |row|
    row_date = row[0]
    row_date > date
  end
  self
end
trim_start(date) click to toggle source
# File lib/quandl/data/operations.rb, line 153
def trim_start(date)
  clone.trim_start!(date)
end
trim_start!(date) click to toggle source
# File lib/quandl/data/operations.rb, line 57
def trim_start!(date)
  # date format
  date = Quandl::Operation::QDate.parse(date)
  # reject rows with dates less than
  self.data_array = to_date!.sort_descending!.delete_if do |row|
    row_date = row[0]
    row_date < date
  end
  self
end