Class: CTioga2::Graphics::Styles::StyleSheet::XPathElement
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Styles::StyleSheet::XPathElement
- Defined in:
- lib/ctioga2/graphics/styles/stylesheet.rb
Overview
An element in a XPath
Instance Attribute Summary collapse
-
#direct_parent ⇒ Object
If this flag is on, the object has to be the direct parent of the child below.
-
#obj_class ⇒ Object
The class – or nil if not selecting on class.
-
#obj_id ⇒ Object
The ID, or nil if not selecting on id.
-
#obj_type ⇒ Object
The type – or nil if not selecting on type.
Class Method Summary collapse
Instance Method Summary collapse
- #matches?(obj) ⇒ Boolean
-
#parse_string(txt) ⇒ Object
A XPathElement is a series of elements (w and - allowed), optionnally followed by a > sign.
- #to_s ⇒ Object
Instance Attribute Details
#direct_parent ⇒ Object
If this flag is on, the object has to be the direct parent of the child below.
44 45 46 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 44 def direct_parent @direct_parent end |
#obj_class ⇒ Object
The class – or nil if not selecting on class
37 38 39 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 37 def obj_class @obj_class end |
#obj_id ⇒ Object
The ID, or nil if not selecting on id
40 41 42 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 40 def obj_id @obj_id end |
#obj_type ⇒ Object
The type – or nil if not selecting on type
34 35 36 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 34 def obj_type @obj_type end |
Class Method Details
.from_text(txt) ⇒ Object
73 74 75 76 77 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 73 def self.from_text(txt) a = XPathElement.new a.parse_string(txt) return a end |
Instance Method Details
#matches?(obj) ⇒ Boolean
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 79 def matches?(obj) if @obj_type && (obj.style_name != @obj_type) return false end if @obj_class && !obj.object_classes.include?(@obj_class) return false end if @obj_id && (obj.object_id != @obj_id) return false end return true end |
#parse_string(txt) ⇒ Object
A XPathElement is a series of elements (w and - allowed), optionnally followed by a > sign. No space allowed, excepted before the > sign
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 49 def parse_string(txt) rest = txt.gsub(/([.#]?)([\w-]+)/) do |x| if $1 == "." @obj_class = $2 elsif $1 == "#" @obj_id = $2 else @obj_type = $2 end "" end if rest =~ /^\s*\*?\s*(>)?$/ if $1 == ">" @direct_parent = true end else raise "Incorrect XPath element: #{txt}" end end |
#to_s ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 92 def to_s a = @obj_type || "" if @obj_id a += "##{@obj_id}" end if @obj_class a += ".#{@obj_class}" end if a.size == 0 a = "*" end if @direct_parent a += " >" end return a end |