Module: Quandl::Format::Dataset::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Quandl::Format::Dataset
- Defined in:
- lib/quandl/format/dataset/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #assign_attributes(attrs) ⇒ Object
- #attributes ⇒ Object
- #column_names ⇒ Object
- #column_names=(names) ⇒ Object
- #data=(rows) ⇒ Object
- #description=(value) ⇒ Object
- #full_code ⇒ Object
- #full_code=(value) ⇒ Object
- #initialize(*args) ⇒ Object
- #meta_attributes ⇒ Object
- #to_qdf ⇒ Object
Instance Method Details
#assign_attributes(attrs) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/quandl/format/dataset/attributes.rb', line 40 def assign_attributes(attrs) attrs.each do |key, value| raise_unknown_attribute_error!(key) unless respond_to?(key) self.send("#{key}=", value) end end |
#attributes ⇒ Object
84 85 86 |
# File 'lib/quandl/format/dataset/attributes.rb', line 84 def attributes self.class.attribute_names.inject({}){|m,k| m[k] = self.send(k) unless self.send(k).nil?; m } end |
#column_names ⇒ Object
68 69 70 |
# File 'lib/quandl/format/dataset/attributes.rb', line 68 def column_names @column_names ||= [] end |
#column_names=(names) ⇒ Object
72 73 74 |
# File 'lib/quandl/format/dataset/attributes.rb', line 72 def column_names=(names) @column_names = Array(names).flatten.collect{|n| n.strip.rstrip } end |
#data=(rows) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/quandl/format/dataset/attributes.rb', line 61 def data=(rows) rows = rows.to_table if rows.respond_to?(:to_table) @data = Quandl::Data.new(rows) self.column_names = @data.headers if @data.headers.present? @data end |
#description=(value) ⇒ Object
57 58 59 |
# File 'lib/quandl/format/dataset/attributes.rb', line 57 def description=(value) @description = value.to_s.gsub('\n', "\n") end |
#full_code ⇒ Object
53 54 55 |
# File 'lib/quandl/format/dataset/attributes.rb', line 53 def full_code [source_code, code].collect{|v| v.blank? ? nil : v }.compact.join('/') end |
#full_code=(value) ⇒ Object
47 48 49 50 51 |
# File 'lib/quandl/format/dataset/attributes.rb', line 47 def full_code=(value) value = value.split('/') self.source_code = value[0] self.code = value[1] end |
#initialize(*args) ⇒ Object
35 36 37 38 |
# File 'lib/quandl/format/dataset/attributes.rb', line 35 def initialize(*args) attrs = args. assign_attributes(attrs) if attrs.is_a?(Hash) end |
#meta_attributes ⇒ Object
80 81 82 |
# File 'lib/quandl/format/dataset/attributes.rb', line 80 def self.class..inject({}){|m,k| m[k] = self.send(k); m } end |
#to_qdf ⇒ Object
76 77 78 |
# File 'lib/quandl/format/dataset/attributes.rb', line 76 def to_qdf Dump.record(self) end |