Class: Emfsvg::Svg::ClipPathRegistry
- Inherits:
-
Object
- Object
- Emfsvg::Svg::ClipPathRegistry
- Defined in:
- lib/emfsvg/svg/clip_path_registry.rb
Overview
Resolves clip-path="url(#X)" references to ClipPath value
objects. Built once per Svg::Document by walking the
Constant Summary collapse
- URL_RE =
/\Aurl\(\s*#([^)\s]+)\s*\)\z/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ClipPathRegistry
constructor
A new instance of ClipPathRegistry.
- #lookup(clip_path_attr) ⇒ Object
- #register(clip_path) ⇒ Object
Constructor Details
#initialize ⇒ ClipPathRegistry
Returns a new instance of ClipPathRegistry.
12 13 14 |
# File 'lib/emfsvg/svg/clip_path_registry.rb', line 12 def initialize @clip_paths = {} end |
Class Method Details
.collect_clip_paths(element, registry) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/emfsvg/svg/clip_path_registry.rb', line 35 def self.collect_clip_paths(element, registry) return unless element registry.register(element) if element.is_a?(Elements::ClipPath) element.children.each { |c| collect_clip_paths(c, registry) } end |
.from_document(document) ⇒ Object
29 30 31 32 33 |
# File 'lib/emfsvg/svg/clip_path_registry.rb', line 29 def self.from_document(document) registry = new collect_clip_paths(document.root_element, registry) registry end |
Instance Method Details
#lookup(clip_path_attr) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/emfsvg/svg/clip_path_registry.rb', line 20 def lookup(clip_path_attr) return nil if clip_path_attr.nil? match = clip_path_attr.match(URL_RE) return nil unless match @clip_paths[match[1]] end |
#register(clip_path) ⇒ Object
16 17 18 |
# File 'lib/emfsvg/svg/clip_path_registry.rb', line 16 def register(clip_path) @clip_paths[clip_path.id] = clip_path end |