Class: Quandl::Cassandra::Models::Column::Read::Transform

Inherits:
Quandl::Cassandra::Models::Column::Read show all
Defined in:
lib/quandl/cassandra/models/column/read/transform.rb

Instance Method Summary collapse

Methods inherited from Quandl::Cassandra::Models::Column::Read

#column_collapses, #column_ids, #column_ids=, #count?, perform

Instance Method Details

#apply_cumulObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 10

def apply_cumul
  # rdiff_from needs the data from the current to offset
  return unless transform?( :cumul ) && limit.present?    
  # data table needs to handle the offset since cumul requires all data
  attributes[:data_table] = Quandl::Cassandra::Models::Column::Read::Offset.call(attributes)
  # the query should not limit or offset the data
  attributes[:row] = nil
  attributes[:limit] = nil
  attributes[:offset] = nil
end

#apply_rdiffObject



21
22
23
24
25
26
27
28
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 21

def apply_rdiff
  return unless transform? :rdiff, :diff
  # limit requires limit
  attributes[:limit] = attributes[:limit] + 1 if attributes[:limit]
  # trims should be increased by one
  attributes[:trim_start] = trim_start.occurrences_of_frequency_ago( 1, attributes[:collapse] ).jd if trim_start.present? && order == :desc
  attributes[:trim_end] = trim_end.occurrences_of_frequency_ahead( 1, attributes[:collapse] ).jd if trim_end.present? && order == :asc
end

#limitObject



45
46
47
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 45

def limit
  attributes[:limit]
end

#orderObject



49
50
51
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 49

def order
  @order ||= attributes[:order] == :asc ? :asc : :desc
end

#performObject



3
4
5
6
7
8
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 3

def perform
  return unless attributes[:transform].present?
  # apply
  apply_rdiff
  apply_cumul
end

#transform?(*keys) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 30

def transform?(*keys)
  keys.each do |key|
    return true if key == attributes[:transform]
  end
  false
end

#trim_endObject



37
38
39
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 37

def trim_end
  @trim_end ||= attributes[:trim_end].present? ? Date.jd( attributes[:trim_end] ) : nil
end

#trim_startObject



41
42
43
# File 'lib/quandl/cassandra/models/column/read/transform.rb', line 41

def trim_start
  @trim_start ||= attributes[:trim_start].present? ? Date.jd( attributes[:trim_start] ) : nil
end