Class: CTioga2::Graphics::Styles::StyleSheet::XPath

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/stylesheet.rb

Overview

An XPath, ie a series of XPathElement from outermost to innermost.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elementsObject

From the innermost to outermost



128
129
130
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 128

def elements
  @elements
end

Class Method Details

.from_text(txt) ⇒ Object



136
137
138
139
140
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 136

def self.from_text(txt)
  a = XPath.new
  a.parse_string(txt)
  return a
end

Instance Method Details

#matches?(obj) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 151

def matches?(obj)
  return match_chain(obj, @elements)
end

#parse_string(txt) ⇒ Object



130
131
132
133
134
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 130

def parse_string(txt)
  @elements = txt.gsub(/\s*>/, '>').split(/\s+/).reverse.map do |x|
    XPathElement.from_text(x)
  end
end

#to_sObject

Returns a normalized version of the XPATH, that can be used as a hash key.



157
158
159
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 157

def to_s
  return @elements.reverse.map { |x| x.to_s }.join(" ")
end

#typed?Boolean

Returns true if the innermost element has a type

Returns:

  • (Boolean)


143
144
145
146
147
148
149
# File 'lib/ctioga2/graphics/styles/stylesheet.rb', line 143

def typed?
  if @elements.first.obj_type
    return true
  else
    return false
  end
end