Class: Kiba::Extend::Utils::ExtractFractions
- Inherits:
-
Object
- Object
- Kiba::Extend::Utils::ExtractFractions
- Defined in:
- lib/kiba/extend/utils/extract_fractions.rb
Overview
Extracts Data::ConvertibleFraction(s) from given String and returns only fractions that can be converted to decimal, in the order they will need to be replaced in the string
Instance Method Summary collapse
-
#call(value) ⇒ Object
-
#initialize(whole_fraction_sep: [" ", "-"]) ⇒ ExtractFractions
constructor
A new instance of ExtractFractions.
Constructor Details
#initialize(whole_fraction_sep: [" ", "-"]) ⇒ ExtractFractions
Returns a new instance of ExtractFractions.
21 22 23 24 25 |
# File 'lib/kiba/extend/utils/extract_fractions.rb', line 21 def initialize(whole_fraction_sep: [" ", "-"]) @whole_fraction_sep = whole_fraction_sep @fpattern = /(\d+\/\d+)/ @fraction = Kiba::Extend::Data::ConvertibleFraction end |
Instance Method Details
#call(value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kiba/extend/utils/extract_fractions.rb', line 28 def call(value) return [] unless value.match?(fpattern) result = [] scanner = StringScanner.new(value) scan(scanner, result) result.each do |fraction| unless fraction.convertible? # rubocop:todo Layout/LineLength warn("#{self.class.name}: Unconvertible fraction: #{value[fraction.position]}") # rubocop:enable Layout/LineLength end end result.sort.reverse end |