Sha256: 088443a425151896a78312ea0544d504e491807cafcb81ff873ba1c846e2fb9e

Contents?: true

Size: 650 Bytes

Versions: 5

Compression:

Stored size: 650 Bytes

Contents

module Teacup
  module_function
  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.slice(location+1, amount.size).gsub(' ', '').to_f
      percent = amount.slice(0, location).to_f / 100.0

      case dimension
      when :width
        (view.superview.frame.size.width * percent + offset).round
      when :height
        (view.superview.frame.size.height * percent + offset).round
      else
        raise "Unknown dimension #{dimension}"
      end
    else
      amount
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
teacup-3.0.1 lib/teacup/calculations.rb
teacup-3.0.0 lib/teacup/calculations.rb
teacup-2.3.0 lib/teacup/calculations.rb
teacup-2.2.2 lib/teacup/calculations.rb
teacup-2.2.0 lib/teacup/calculations.rb