Class: Quandl::Cassandra::Models::Column::Read::Type

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

Instance Method Summary collapse

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

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

Instance Method Details

#date_typesObject



27
28
29
# File 'lib/quandl/cassandra/models/column/read/type.rb', line 27

def date_types
  [:trim_start, :trim_end]
end

#enforce_type(key, value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/quandl/cassandra/models/column/read/type.rb', line 12

def enforce_type(key, value)
  case key
  when *date_types      then parse_date(value)
  when *integer_types   then value.try(:to_i)
  when *sym_types       then value.try(:to_sym)
  when :order           then value.try(:to_sym) == :asc ? :asc : :desc
  else
    value
  end
end

#integer_typesObject



31
32
33
# File 'lib/quandl/cassandra/models/column/read/type.rb', line 31

def integer_types
  [:limit, :column, :offset, :accuracy, :row]
end

#parse_date(value) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/quandl/cassandra/models/column/read/type.rb', line 35

def parse_date(value)
  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
rescue
  nil
end

#performObject



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

def perform
  # enforce types
  attributes.each do |key, value|
    attributes[key] = enforce_type(key, value)
  end
  # retain pristine copy of attrs
  attributes[:pristine] ||= attributes.clone
end

#sym_typesObject



23
24
25
# File 'lib/quandl/cassandra/models/column/read/type.rb', line 23

def sym_types
  [:collapse, :transform, :frequency]
end