Class: WorkerTools::XlsxInput::XlsxInputForeach
- Inherits:
-
Object
- Object
- WorkerTools::XlsxInput::XlsxInputForeach
- Includes:
- Enumerable
- Defined in:
- lib/worker_tools/xlsx_input.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(rows_enum:, mapping_order:, cleanup_method:, headers_present:) ⇒ XlsxInputForeach
constructor
A new instance of XlsxInputForeach.
- #values_to_row(values) ⇒ Object
Constructor Details
#initialize(rows_enum:, mapping_order:, cleanup_method:, headers_present:) ⇒ XlsxInputForeach
Returns a new instance of XlsxInputForeach.
161 162 163 164 165 166 |
# File 'lib/worker_tools/xlsx_input.rb', line 161 def initialize(rows_enum:, mapping_order:, cleanup_method:, headers_present:) @rows_enum = rows_enum @mapping_order = mapping_order @cleanup_method = cleanup_method @headers_present = headers_present end |
Instance Method Details
#each ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/worker_tools/xlsx_input.rb', line 168 def each return enum_for(:each) unless block_given? @rows_enum.with_index.each do |values, index| next if index.zero? && @headers_present yield values_to_row(values) end end |
#values_to_row(values) ⇒ Object
178 179 180 181 182 |
# File 'lib/worker_tools/xlsx_input.rb', line 178 def values_to_row(values) @mapping_order.each_with_object(HashWithIndifferentAccess.new) do |(k, v), h| h[k] = @cleanup_method.call(values[v].try(:value)) end end |