Skip to content

Commit

Permalink
Initializing with a dimension should copy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
quirkey committed Jun 28, 2009
1 parent f0cde41 commit 21d0fcb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/qcontent/dimension.rb
Expand Up @@ -14,15 +14,15 @@ def initialize(*args)
self.width = first['width'] || first[:width]
self.height = first['height'] || first[:height]
self.name = first['name'] || first[:name]
when Dimension
return first
when Qcontent::Dimension
self.name, self.width, self.height = first.name, first.width, first.height
when Fixnum
self.width = first
self.height = args.shift
else
if first.to_i == 0 # its a name
self.name = first
d = Dimension.new(*args)
d = Qcontent::Dimension.new(*args)
self.width, self.height = d.width, d.height
else
self.width, self.height = (first.is_a?(String) ? first.split('x') : first)
Expand All @@ -47,14 +47,18 @@ def height=(h)
def to_s(join = 'x')
name ? name : dimension_s(join)
end

def to_a
[width, height]
end

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

def to_a
[width, height]
def inspect
"<Dimension: #{name}, #{dimension_s}>"
end

end
end
20 changes: 20 additions & 0 deletions test/test_dimension.rb
Expand Up @@ -23,6 +23,26 @@ class TestDimension < Test::Unit::TestCase

end

context "with a dimension" do
setup do
@dimension = Qcontent::Dimension.new(Qcontent::Dimension.new('400','300'))
end

should "set width" do
assert_equal 400, @dimension.width
end

should "set height" do
assert_equal 300, @dimension.height
end

should "set name" do
assert_equal '400x300', @dimension.name
end

end


context "with two integers as arguments" do
setup do
@dimension = Qcontent::Dimension.new(400,300)
Expand Down

0 comments on commit 21d0fcb

Please sign in to comment.