Class: Plotrb::Data::Format

Inherits:
Object show all
Includes:
Base
Defined in:
lib/plotrb/data.rb

Instance Method Summary collapse

Methods included from Base

#add_attributes, #attributes, #classify, #collect_attributes, #define_boolean_attribute, #define_boolean_attributes, #define_multi_val_attribute, #define_multi_val_attributes, #define_single_val_attribute, #define_single_val_attributes, #defined_attributes, included, #set_attributes

Constructor Details

#initialize(type, &block) ⇒ Format

Returns a new instance of Format.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/plotrb/data.rb', line 136

def initialize(type, &block)
  case type
    when :json
      add_attributes(:parse, :property)
      define_single_val_attributes(:parse, :property)
    when :csv, :tsv
      add_attributes(:parse)
      define_single_val_attribute(:parse)
    when :topojson
      add_attributes(:feature, :mesh)
      define_single_val_attributes(:feature, :mesh)
    when :treejson
      add_attributes(:parse, :children)
      define_single_val_attributes(:parse, :children)
    else
      raise ArgumentError, 'Invalid Data format'
  end
  @type = type
  self.instance_eval(&block) if block_given?
  self
end

Instance Method Details

#boolean(*field, &block) ⇒ Object Also known as: as_boolean



174
175
176
177
178
179
# File 'lib/plotrb/data.rb', line 174

def boolean(*field, &block)
  @parse ||= {}
  field.flatten.each { |f| @parse.merge!(f => :boolean) }
  self.instance_eval(&block) if block_given?
  self
end

#date(*field, &block) ⇒ Object Also known as: as_date



158
159
160
161
162
163
# File 'lib/plotrb/data.rb', line 158

def date(*field, &block)
  @parse ||= {}
  field.flatten.each { |f| @parse.merge!(f => :date) }
  self.instance_eval(&block) if block_given?
  self
end

#number(*field, &block) ⇒ Object Also known as: as_number



166
167
168
169
170
171
# File 'lib/plotrb/data.rb', line 166

def number(*field, &block)
  @parse ||= {}
  field.flatten.each { |f| @parse.merge!(f => :number) }
  self.instance_eval(&block) if block_given?
  self
end