Class: Eco::API::UseCases::OozeSamples::Helpers::ExportableRegister
- 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #add_ooze(ooze) ⇒ Object
- #each(as_values: true, as_row: false, &block) ⇒ Object
- #empty? ⇒ Boolean
- #header(refresh: false) ⇒ Object
-
#initialize(**options) ⇒ ExportableRegister
constructor
A new instance of ExportableRegister.
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 = .merge({ delimiter: "\n", only_indexed: true, only_labeled: true, only_with_ref: true }) end |
Instance Attribute Details
#options ⇒ Object (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 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, **) 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
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 55 |
# 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 |