Refactoring out the unit conversion to its own place

This commit is contained in:
Andy Meneely
2015-02-01 23:48:09 -05:00
parent 4ecbaa4e31
commit 1896689614
3 changed files with 45 additions and 6 deletions
+21
View File
@@ -0,0 +1,21 @@
require 'squib/constants'
module Squib
module Args
module UnitConversion
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 /cm$/ #ends with "cm"
arg.rstrip[0..-2].to_f * dpi * INCHES_IN_CM
else
arg
end
end
end
end
end
+2 -6
View File
@@ -1,4 +1,5 @@
require 'squib/constants'
require 'squib/args/unit_conversion'
module Squib
# :nodoc:
@@ -200,12 +201,7 @@ module Squib
Squib::UNIT_CONVERSION_PARAMS.each_pair do |param_name, api_param|
if needed_params.include? param_name
opts[api_param].each_with_index do |arg, i|
case arg.to_s.rstrip
when /in$/ #ends with "in"
opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi
when /cm$/ #ends with "cm"
opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi * Squib::INCHES_IN_CM
end
opts[api_param][i] = Args::UnitConversion.parse(arg, @dpi)
end
end
end