Sha256: f5685f94bad836cf80631c9efb90681db421d2b6351c4a7251ca6b8edc778c1b

Contents?: true

Size: 688 Bytes

Versions: 6

Compression:

Stored size: 688 Bytes

Contents

require_relative '../constants'

module Squib
  module Args
    # :nodoc:
    # @api private
    module UnitConversion

      # :nodoc:
      # @api private
      module_function
      def parse(arg, dpi=300)
        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
        else
          arg
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
squib-0.15.3 lib/squib/args/unit_conversion.rb
squib-0.15.0 lib/squib/args/unit_conversion.rb
squib-0.14.3.pre1 lib/squib/args/unit_conversion.rb
squib-0.14.1 lib/squib/args/unit_conversion.rb
squib-0.14.0 lib/squib/args/unit_conversion.rb
squib-0.14.beta1 lib/squib/args/unit_conversion.rb