Class: Plotrb::Data
Overview
The basic tabular data model used by Vega. See https://github.com/trifacta/vega/wiki/Data
Defined Under Namespace
Classes: Format
Instance Method Summary collapse
- #extra_fields ⇒ Object
- #format(*args, &block) ⇒ Object
-
#initialize(&block) ⇒ Data
constructor
A new instance of Data.
- #method_missing(method, *args, &block) ⇒ Object
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(&block) ⇒ Data
Returns a new instance of Data.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/plotrb/data.rb', line 23 def initialize(&block) define_single_val_attributes(:name, :values, :source, :url) define_multi_val_attribute(:transform) self.singleton_class.class_eval { alias_method :file, :url } self.instance_eval(&block) if block_given? ::Plotrb::Kernel.data << self self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/plotrb/data.rb', line 55 def method_missing(method, *args, &block) case method.to_s # set format of the data when /^as_(csv|tsv|json|topojson|treejson)$/ self.format($1.to_sym, &block) else super end end |
Instance Method Details
#extra_fields ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/plotrb/data.rb', line 46 def extra_fields @extra_fields ||= [:data, :index] if @transform @extra_fields.concat(@transform.collect { |t| t.extra_fields }). flatten!.uniq! end @extra_fields end |