class Castaway::Size

Public Instance Methods

*(factor) click to toggle source
# File lib/castaway/size.rb, line 4
def *(factor)
  if factor.is_a?(Size)
    Size.new(width * factor.width, height * factor.height)
  else
    Size.new(width * factor, height * factor)
  end
end
aspect_ratio() click to toggle source
# File lib/castaway/size.rb, line 20
def aspect_ratio
  @aspect_ratio ||= width.to_f / height
end
empty?() click to toggle source
# File lib/castaway/size.rb, line 16
def empty?
  (width || 0).zero? && (height || 0).zero?
end
present?() click to toggle source
# File lib/castaway/size.rb, line 12
def present?
  width || height
end
to_geometry() click to toggle source
# File lib/castaway/size.rb, line 36
def to_geometry
  format('%.2fx%.2f', width, height).tap do |geometry|
    geometry << '!' if width && height
  end
end
to_resolution() click to toggle source
# File lib/castaway/size.rb, line 42
def to_resolution
  format('%dx%d', width || 0, height || 0)
end
to_s() click to toggle source
# File lib/castaway/size.rb, line 32
def to_s
  format('(%.2f, %.2f)', width, height)
end
with_height(height) click to toggle source
# File lib/castaway/size.rb, line 24
def with_height(height)
  Size.new((aspect_ratio * height).to_i, height.to_i)
end
with_width(width) click to toggle source
# File lib/castaway/size.rb, line 28
def with_width(width)
  Size.new(width.to_i, (width / aspect_ratio).to_i)
end