lib/bulldog/style.rb in bulldog-0.1.1 vs lib/bulldog/style.rb in bulldog-0.2.0
- old
+ new
@@ -1,10 +1,14 @@
module Bulldog
+ #
+ # Represents a style to generate.
+ #
class Style
def initialize(name, attributes={})
@name = name
@attributes = attributes
+ set_dimensions(attributes[:size])
end
attr_reader :name, :attributes
#
@@ -13,11 +17,16 @@
delegate :[], :to => :attributes
#
# Set the value of the given style attribute.
#
- delegate :[]=, :to => :attributes
+ def []=(name, value)
+ if name == :size
+ set_dimensions(value)
+ end
+ attributes[name] = value
+ end
#
# Return true if the argument is a Style with the same name and
# attributes.
#
@@ -30,9 +39,27 @@
def inspect
"#<Style #{name.inspect} #{attributes.inspect}>"
end
delegate :hash, :eql?, :to => :name
+
+ #
+ # The [width, height] specified by :size, or nil if there is no :size.
+ #
+ attr_reader :dimensions
+
+ #
+ # Return true if :filled is true, false otherwise.
+ #
+ def filled?
+ !!self[:filled]
+ end
+
+ private
+
+ def set_dimensions(value)
+ @dimensions = value ? value.scan(/\A(\d+)x(\d+)\z/).first.map{|s| s.to_i} : nil
+ end
ORIGINAL = new(:original, {})
end
end