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.



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

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.



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

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

#set(styles) ⇒ Object



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

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