Sha256: 96a849f424cc4349cabf6faa683c547ca5f4a7864337ed1ab2c4592b5e92da8f

Contents?: true

Size: 634 Bytes

Versions: 3

Compression:

Stored size: 634 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
      when :height
        view.superview.frame.size.height * percent + offset
      else
        raise "Unknown dimension #{dimension}"
      end
    else
      amount
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
teacup-2.1.16 lib/teacup/calculations.rb
teacup-2.1.15 lib/teacup/calculations.rb
teacup-2.1.14 lib/teacup/calculations.rb