class Daru::IO::Importers::Base
Base
Importer Class that contains generic helper methods, to be used by other Importers
via inheritence
Public Class Methods
Adds the `from` class method to all inheriting children Importer classes, which calls corresponding Importer's `initialize` and instance method `from`.
# File lib/daru/io/importers/base.rb, line 50 def self.from(relation) new.from(relation) end
Guesses the `Daru::DataFrame` from the parsed set of key-value pairs.
@param keys [Array] A set of keys from given key-value pairs @param vals [Array] A set of values from given key-value pairs
@example When key-value pairs contains values that is Array of Hashes
Daru::IO::Importers::Base.guess_parse([:a], [[{ x: 1, y: 2 },{ x: 3, y: 4 }]]) #=> #<Daru::DataFrame(2x2)> # x y # 0 1 2 # 1 3 4
@example When key-value pairs contains values that is Arrays
Daru::IO::Importers::Base.guess_parse([:x, :y], [[1,3], [2,4]]) #=> #<Daru::DataFrame(2x2)> # x y # 0 1 2 # 1 3 4
@example When key-value pairs contains Array of keys contain value Hashes
Daru::IO::Importers::Base.guess_parse([:a, :b], [{ x: 1, y: 2 }, { x: 3, y: 4 }]) #=> #<Daru::DataFrame(2x2)> # x y # a 1 2 # b 3 4
# File lib/daru/io/importers/base.rb, line 37 def self.guess_parse(keys, vals) case vals.first when Array case vals.first.first when Hash then Daru::DataFrame.new(vals.flatten) else Daru::DataFrame.rows(vals.transpose, order: keys) end when Hash then Daru::DataFrame.new(vals.flatten, index: keys) end end
Adds the `read` class method to all inheriting children Importer classes, which calls corresponding Importer's `initialize` and instance method `read`.
# File lib/daru/io/importers/base.rb, line 56 def self.read(path) new.read(path) end