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.
167 168 169 170 171 172 |
# File 'lib/worker_tools/xlsx_input.rb', line 167 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
174 175 176 177 178 179 180 181 182 |
# File 'lib/worker_tools/xlsx_input.rb', line 174 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
184 185 186 187 188 |
# File 'lib/worker_tools/xlsx_input.rb', line 184 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 |