Class: Daru::DataFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/daru/io/link.rb

Class Method Summary collapse

Class Method Details

.register_io_module(function, instance = nil, &block) ⇒ Object

Links Daru::DataFrame Import / Export methods to corresponding Daru::IO Importer / Exporter classes. Here is the list of linkages:

Importers

Daru::DataFrame method Daru::IO::Importers class
Daru::DataFrame.from_activerecord IO::Importers::ActiveRecord#from
Daru::DataFrame.read_avro IO::Importers::Avro#read
Daru::DataFrame.read_csv IO::Importers::CSV#read
Daru::DataFrame.read_excel IO::Importers::Excel#read,
IO::Importers::Excelx#read
Daru::DataFrame.read_html IO::Importers::HTML#read
Daru::DataFrame.from_json IO::Importers::JSON#from
Daru::DataFrame.read_json IO::Importers::JSON#read
Daru::DataFrame.from_mongo IO::Importers::Mongo#from
Daru::DataFrame.read_plaintext IO::Importers::Plaintext#read
Daru::DataFrame.read_rdata IO::Importers::RData#read
Daru::DataFrame.read_rds IO::Importers::RDS#read
Daru::DataFrame.from_redis IO::Importers::Redis#from
Daru::DataFrame.from_sql IO::Importers::SQL#from

Exporters

Daru::DataFrame instance method Daru::IO::Exporters class
Daru::DataFrame.to_avro_string IO::Exporters::Avro#to_s
Daru::DataFrame.write_avro IO::Exporters::Avro#write
Daru::DataFrame.to_csv_string IO::Exporters::CSV#to_s
Daru::DataFrame.write_csv IO::Exporters::CSV#write
Daru::DataFrame.to_excel_string IO::Exporters::Excel#to_s
Daru::DataFrame.write_excel IO::Exporters::Excel#write
Daru::DataFrame.to_json IO::Exporters::JSON#to
Daru::DataFrame.to_json_string IO::Exporters::JSON#to_s
Daru::DataFrame.write_json IO::Exporters::JSON#write
Daru::DataFrame.to_rds_string IO::Exporters::RDS#to_s
Daru::DataFrame.write_rds IO::Exporters::RDS#write
Daru::DataFrame.to_sql IO::Exporters::SQL#to

Parameters:

  • function (Symbol)

    Functon name to be monkey-patched into +Daru::DataFrame+

  • instance (Class) (defaults to: nil)

    The Daru-IO class to be linked to monkey-patched function

Returns:

  • A Daru::DataFrame class method in case of Importer, and instance variable method in case of Exporter.



48
49
50
51
52
53
54
55
56
# File 'lib/daru/io/link.rb', line 48

def register_io_module(function, instance=nil, &block)
  return define_singleton_method(function, &block) if block_given?

  case function.to_s
  when /\Ato_.*_string\Z/, /\Ato_/, /\Awrite_/ then register_exporter(function, instance)
  when /\Afrom_/, /\Aread_/                    then register_importer(function, instance)
  else raise ArgumentError, 'Invalid function name given to monkey-patch into Daru::DataFrame.'
  end
end