Module: Squib::Args::UnitConversion Private

Defined in:
lib/squib/args/unit_conversion.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

:nodoc:

Class Method Summary collapse

Class Method Details

.parse(arg, dpi = 300) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/squib/args/unit_conversion.rb', line 12

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