Class: Eco::API::UseCases::OozeSamples::Helpers::ExportableRegister

Inherits:
Object
  • Object
show all
Includes:
OozeHandlers, Enumerable
Defined in:
lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb

Overview

Class to ease the export process

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OozeHandlers

#array_indexes, #merge_arrays, #merge_values

Constructor Details

#initialize(**options) ⇒ ExportableRegister

Returns a new instance of ExportableRegister.



13
14
15
16
17
18
19
20
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 13

def initialize(**options)
  @options = options.merge({
    delimiter:     "\n",
    only_indexed:  true,
    only_labeled:  true,
    only_with_ref: true
  })
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 8

def options
  @options
end

Instance Method Details

#add_ooze(ooze) ⇒ Object



22
23
24
25
26
27
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 22

def add_ooze(ooze)
  ooz             = ExportableOoze.new(ooze, **options)
  data            = ooz.key_typed_data
  @typed_header   = merge_arrays(data.keys, typed_header)
  key_typed_data << data
end

#each(as_values: true, as_row: false, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 33

def each(as_values: true, as_row: false, &block)
  return to_enum(:each, as_values: as_values, as_row: as_row) unless block

  key_typed_data.each do |ooze_data|
    values = ooze_data.values_at(*typed_header)

    if as_values
      values
    elsif as_row
      ::CSV::Row.new(values, header)
    else
      header.zip(values)
    end.tap(&block)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 29

def empty?
  count < 1
end

#header(refresh: false) ⇒ Object



49
50
51
52
53
54
# File 'lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb', line 49

def header(refresh: false)
  return @header if instance_variable_defined?(:@header) && !refresh
  @header = typed_header.map do |name|
    ExportableOoze.key_to_label(name)
  end
end