Merge pull request #166 from felixleong/feature/remove-unit-conversion-redundancy

Remove redundant `ArgLoader.convert_unit` to `UnitConversion.parse`.
This commit is contained in:
Andy Meneely
2016-08-01 16:27:41 -04:00
committed by GitHub
2 changed files with 3 additions and 15 deletions
+2 -14
View File
@@ -111,27 +111,15 @@ module Squib
p_str = "@#{p}" p_str = "@#{p}"
p_val = instance_variable_get(p_str) p_val = instance_variable_get(p_str)
if p_val.respond_to? :each if p_val.respond_to? :each
arr = p_val.map { |x| convert_unit(x, dpi) } arr = p_val.map { |x| UnitConversion.parse(x, dpi) }
instance_variable_set p_str, arr instance_variable_set p_str, arr
else else
instance_variable_set p_str, convert_unit(p_val, dpi) instance_variable_set p_str, UnitConversion.parse(p_val, dpi)
end end
end end
self self
end end
def convert_unit(arg, dpi)
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
module_function :convert_unit
end end
end end
+1 -1
View File
@@ -59,7 +59,7 @@ module Squib
def validate_dash(arg, _i) def validate_dash(arg, _i)
arg.to_s.split.collect do |x| arg.to_s.split.collect do |x|
convert_unit(x, @dpi).to_f UnitConversion.parse(x, @dpi).to_f
end end
end end