class Plotrb::Data::Format

Public Class Methods

new(type, &block) click to toggle source
# 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

Public Instance Methods

as_boolean(*field, &block)
Alias for: boolean
as_date(*field, &block)
Alias for: date
as_number(*field, &block)
Alias for: number
boolean(*field, &block) click to toggle source
# 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
Also aliased as: as_boolean
date(*field, &block) click to toggle source
# 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
Also aliased as: as_date
number(*field, &block) click to toggle source
# 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
Also aliased as: as_number

Private Instance Methods

attribute_post_processing() click to toggle source
# File lib/plotrb/data.rb, line 184
def attribute_post_processing
  process_parse
  process_property
  process_feature
  process_mesh
  process_children
end
process_children() click to toggle source
# File lib/plotrb/data.rb, line 221
def process_children
  return unless @children
  unless @children.is_a?(String)
    raise ArgumentError, 'Invalid TreeJSON children'
  end
end
process_feature() click to toggle source
# File lib/plotrb/data.rb, line 207
def process_feature
  return unless @feature
  unless @feature.is_a?(String)
    raise ArgumentError, 'Invalid TopoJSON feature'
  end
end
process_mesh() click to toggle source
# File lib/plotrb/data.rb, line 214
def process_mesh
  return unless @mesh
  unless @mesh.is_a?(String)
    raise ArgumentError, 'Invalid TopoJSON mesh'
  end
end
process_parse() click to toggle source
# File lib/plotrb/data.rb, line 192
def process_parse
  return unless @parse
  valid_type = %i(number boolean date)
  unless @parse.is_a?(Hash) && (@parse.values - valid_type).empty?
    raise ArgumentError, 'Invalid parse options for Data format'
  end
end
process_property() click to toggle source
# File lib/plotrb/data.rb, line 200
def process_property
  return unless @property
  unless @property.is_a?(String)
    raise ArgumentError, 'Invalid JSON property'
  end
end