Sha256: 5b8ea444330e3b68f6c525b35394564db5007bf65ca3ee3fc69ece7c32855db4

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require_relative '../constants'


module Squib
  module Args
    module UnitConversion
      module_function def parse(arg, dpi=300, cell_px=37.5)
        case arg.to_s.rstrip
        when /in$/ # ends with "in"
          arg.rstrip[0..-2].to_f * dpi
        when /pt$/ # ends with "in"
          arg.rstrip[0..-2].to_f * dpi / POINTS_PER_IN
        when /cm$/ # ends with "cm"
          arg.rstrip[0..-2].to_f * dpi * INCHES_IN_CM
        when /mm$/ # ends with "mm"
          arg.rstrip[0..-2].to_f * dpi * INCHES_IN_CM / 10.0
        when /deg$/ # ends with "deg"
          arg.rstrip[0..-3].to_f * (Math::PI / 180.0)
        when /c(ell)?[s]?$/ # ends with 'c', 'cell', or 'cells'
          arg.sub(/c(ell)?[s]?$/, '').to_f * cell_px
        else
          arg
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
squib-0.19.0 lib/squib/args/unit_conversion.rb
squib-0.19.0b lib/squib/args/unit_conversion.rb
squib-0.19.0a lib/squib/args/unit_conversion.rb