Class: Importu::Sources::Ruby

Inherits:
Object
  • Object
show all
Defined in:
lib/importu/sources/ruby.rb

Overview

Uses Ruby objects as import source data.

Accepts an array of hashes or any enumerable that yields objects responding to #to_hash. Hash keys should be strings to match other source formats.

Examples:

Basic usage

data = [{ "name" => "Alice" }, { "name" => "Bob" }]
source = Importu::Sources::Ruby.new(data)
source.rows.each { |row| puts row["name"] }

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Ruby

Creates a new Ruby source.

Parameters:

  • data (Array<Hash>, Enumerable)

    objects that respond to #to_hash



19
20
21
# File 'lib/importu/sources/ruby.rb', line 19

def initialize(data, **)
  @data = data
end

Instance Method Details

#closevoid

This method returns an undefined value.

No-op for Ruby source (no file handles to close).

Provided for API consistency with file-based sources.



44
# File 'lib/importu/sources/ruby.rb', line 44

def close; end

#rowsEnumerator<Hash>

Returns an enumerator that yields each element as a hash.

Returns:

  • (Enumerator<Hash>)

    rows from the data array



26
27
28
29
30
# File 'lib/importu/sources/ruby.rb', line 26

def rows
  Enumerator.new do |yielder|
    @data.each {|row| yielder.yield(row.to_hash) }
  end
end

#write_errors(summary, only_errors: false) ⇒ nil

Not implemented for Ruby source.

Parameters:

  • summary (Importu::Summary)

    the import summary (unused)

  • only_errors (Boolean) (defaults to: false)

    (unused)

Returns:

  • (nil)

    always returns nil



37
# File 'lib/importu/sources/ruby.rb', line 37

def write_errors(summary, only_errors: false); end