Class: Kiba::Extend::Transforms::Fraction::ToDecimal
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Fraction::ToDecimal
- Defined in:
- lib/kiba/extend/transforms/fraction/to_decimal.rb
Overview
Converts fractions expressed like “1 1/4” to decimals like “1.25”
Instance Method Summary collapse
-
#initialize(fields:, targets: nil, target_format: :string, places: 4, whole_fraction_sep: [" ", "-"], delete_sources: false) ⇒ ToDecimal
constructor
A new instance of ToDecimal.
-
#process(row) ⇒ Object
Constructor Details
#initialize(fields:, targets: nil, target_format: :string, places: 4, whole_fraction_sep: [" ", "-"], delete_sources: false) ⇒ ToDecimal
Returns a new instance of ToDecimal.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/kiba/extend/transforms/fraction/to_decimal.rb', line 107 def initialize(fields:, targets: nil, target_format: :string, places: 4, whole_fraction_sep: [" ", "-"], delete_sources: false) @fields = [fields].flatten @targets = targets ? [targets].flatten : nil @target_format = target_format @places = places @delete_sources = delete_sources @extractor = Kiba::Extend::Utils::ExtractFractions.new(whole_fraction_sep: whole_fraction_sep) end |
Instance Method Details
#process(row) ⇒ Object
122 123 124 125 126 |
# File 'lib/kiba/extend/transforms/fraction/to_decimal.rb', line 122 def process(row) fields.each { |field| to_decimal(field, row) } delete_source_fields(row) row end |