Class: PhotoUtils::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/photo_utils/frame.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height, width) ⇒ Frame

Returns a new instance of Frame.



10
11
12
13
14
15
# File 'lib/photo_utils/frame.rb', line 10

def initialize(height, width)
  # correct swapped values
  width, height = height, width if height < width
  @height = Length.new(height)
  @width  = Length.new(width)
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/photo_utils/frame.rb', line 7

def height
  @height
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/photo_utils/frame.rb', line 8

def width
  @width
end

Instance Method Details

#diagonalObject



29
30
31
32
# File 'lib/photo_utils/frame.rb', line 29

def diagonal
  d = Math.sqrt((@height ** 2) + (@width ** 2))
  Length.new(d)
end

#inspectObject



17
18
19
# File 'lib/photo_utils/frame.rb', line 17

def inspect
  "<#{self.class} height=#{@height.inspect} width=#{@width.inspect}>"
end

#to_s(format = :metric) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/photo_utils/frame.rb', line 21

def to_s(format=:metric)
  if @height == Math::Infinity && @width == Math::Infinity
    "n/a"
  else
    "#{@height.to_s(format)} x #{@width.to_s(format)}"
  end
end