Class: Postsvg::Svg::ClipPathRegistry
- Inherits:
-
Object
- Object
- Postsvg::Svg::ClipPathRegistry
- Defined in:
- lib/postsvg/svg/clip_path_registry.rb
Overview
Indexes
Instance Attribute Summary collapse
-
#by_id ⇒ Object
readonly
Returns the value of attribute by_id.
Class Method Summary collapse
- .empty ⇒ Object
-
.from_node(root) ⇒ Object
Build a registry by scanning
rootforchildren.
Instance Method Summary collapse
-
#initialize(by_id = {}) ⇒ ClipPathRegistry
constructor
A new instance of ClipPathRegistry.
- #key?(id) ⇒ Boolean
- #lookup(id) ⇒ Object
Constructor Details
#initialize(by_id = {}) ⇒ ClipPathRegistry
Returns a new instance of ClipPathRegistry.
10 11 12 13 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 10 def initialize(by_id = {}) @by_id = by_id.dup.freeze freeze end |
Instance Attribute Details
#by_id ⇒ Object (readonly)
Returns the value of attribute by_id.
8 9 10 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 8 def by_id @by_id end |
Class Method Details
.empty ⇒ Object
15 16 17 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 15 def self.empty @empty ||= new({}) end |
.from_node(root) ⇒ Object
Build a registry by scanning root for
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 28 def self.from_node(root) registry = {} root.xpath(".//*[local-name()='clipPath']").each do |node| id = node["id"] next unless id # Concatenate the d attributes of all child <path> elements # in document order. Other shape children are converted to # path data lazily; for now we only support <path>. ds = node.xpath(".//*[local-name()='path']").map { |p| p["d"] }.compact registry[id] = ds.join(" ") unless ds.empty? end new(registry) end |
Instance Method Details
#key?(id) ⇒ Boolean
23 24 25 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 23 def key?(id) @by_id.key?(id) end |
#lookup(id) ⇒ Object
19 20 21 |
# File 'lib/postsvg/svg/clip_path_registry.rb', line 19 def lookup(id) @by_id[id] end |