lib/teacup/calculations.rb in teacup-1.2.9 vs lib/teacup/calculations.rb in teacup-1.3.0

- old
+ new

@@ -1,19 +1,23 @@ module Teacup module_function - def calculate(view, dimension, percent) - if percent.is_a? Proc - view.instance_exec(&percent) - elsif percent.is_a? String and percent[-1] == '%' - percent = percent[0...-1].to_f / 100.0 + def calculate(view, dimension, amount) + if amount.is_a? Proc + view.instance_exec(&amount) + elsif amount.is_a?(String) && amount.include?('%') + location = amount.index '%' + offset = amount[(location+1)..-1].gsub(' ', '').to_f + percent = amount[0...location].to_f / 100.0 case dimension when :width - CGRectGetWidth(view.superview.bounds) * percent + CGRectGetWidth(view.superview.bounds) * percent + offset when :height - CGRectGetHeight(view.superview.bounds) * percent + CGRectGetHeight(view.superview.bounds) * percent + offset + else + raise "Unknown dimension #{dimension}" end else - percent + amount end end end