Class: Magick::RVG::Styles

Inherits:
Struct
  • Object
show all
Defined in:
lib/rvg/stylable.rb,
lib/rvg/stylable.rb

Overview

Styles is a Struct class with a couple of extra methods

Instance Method Summary collapse

Instance Method Details

#deep_copy(h = nil) ⇒ Object

The “usual” deep_copy method doesn’t copy a Struct correctly.



44
45
46
47
48
# File 'lib/rvg/stylable.rb', line 44

def deep_copy(h=nil)
    copy = Styles.new
    each_pair { |style, value| copy[style] = value }
    copy
end

#each_valueObject

Iterate over the style names. Yield for each style that has a value.



37
38
39
40
41
# File 'lib/rvg/stylable.rb', line 37

def each_value
    each_pair do |style, value|
        yield(style, value) if value
    end
end

#set(styles) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rvg/stylable.rb', line 21

def set(styles)
    begin
        styles.each_pair do |style, value|
            begin
                self[style] = value
            rescue NoMethodError
                raise ArgumentError, "unknown style `#{style}'"
            end
        end
    rescue NoMethodError
        raise ArgumentError, "style arguments must be in the form `style => value'"
    end
    self
end