Class: Qcontent::Dimension

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/qcontent/dimension.rb

Defined Under Namespace

Classes: InvalidDimension

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Dimension

Returns a new instance of Dimension.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/qcontent/dimension.rb', line 8

def initialize(*args)
  first = args.shift
  case first
  when Array
    self.width, self.height = first
  when Hash
    self.width  = first['width'] || first[:width]
    self.height = first['height'] || first[:height]
  when Dimension
    return first
  else
    self.width, self.height = (first.is_a?(String) ? first.split('x') : first)
    self.height ||= args.shift
  end
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/qcontent/dimension.rb', line 6

def height
  @height
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/qcontent/dimension.rb', line 6

def width
  @width
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/qcontent/dimension.rb', line 24

def ==(other)
  self.width == other.width && self.height == other.height
end

#to_aObject



40
41
42
# File 'lib/qcontent/dimension.rb', line 40

def to_a
  [width, height]
end

#to_s(join = 'x') ⇒ Object



36
37
38
# File 'lib/qcontent/dimension.rb', line 36

def to_s(join = 'x')
  "#{width}#{join}#{height}"
end