Refactoring out the unit conversion to its own place
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user