Sha256: 2dda35e00449ce67fb5466a0c82613cc468efb46f20385c4f9d206551db40970

Contents?: true

Size: 530 Bytes

Versions: 2

Compression:

Stored size: 530 Bytes

Contents

require "galaxy_converter/roman_numeral"

module GalaxyConverter
  class Abacus
    def initialize(mapping = {}, unit = Roman::Numeral)
      @mapping = mapping
      @unit = unit
    end

    def call(units)
      converted = convert(units)
      result = @unit.new(converted)
      return 0 unless result.valid?
      result.to_i
    end

    private def convert(units)
      units.split(" ").reduce("") do |to_convert, unit|
        return unless @mapping[unit]
        to_convert << @mapping[unit]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
galaxy_converter-2.1.2 lib/galaxy_converter/abacus.rb
galaxy_converter-2.1.1 lib/galaxy_converter/abacus.rb