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.



46
47
48
49
50
# File 'lib/rvg/stylable.rb', line 46

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

#each_valueObject

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



39
40
41
42
43
# File 'lib/rvg/stylable.rb', line 39

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

#set(styles) ⇒ Object



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

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