class CTioga2::Graphics::Styles::StyleSheet::XPath

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

Attributes

elements[RW]

From the innermost to outermost

Public Class Methods

from_text(txt) click to toggle source
# File lib/ctioga2/graphics/styles/stylesheet.rb, line 136
def self.from_text(txt)
  a = XPath.new
  a.parse_string(txt)
  return a
end

Public Instance Methods

matches?(obj) click to toggle source
# File lib/ctioga2/graphics/styles/stylesheet.rb, line 151
def matches?(obj)
  return match_chain(obj, @elements)
end
parse_string(txt) click to toggle source
# 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_s() click to toggle source

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

# File lib/ctioga2/graphics/styles/stylesheet.rb, line 157
def to_s
  return @elements.reverse.map { |x| x.to_s }.join(" ")
end
typed?() click to toggle source

Returns true if the innermost element has a type

# File lib/ctioga2/graphics/styles/stylesheet.rb, line 143
def typed?
  if @elements.first.obj_type
    return true
  else
    return false
  end
end

Protected Instance Methods

match_chain(obj, elems) click to toggle source
# File lib/ctioga2/graphics/styles/stylesheet.rb, line 163
def match_chain(obj, elems)
  if ! elems.first.matches?(obj)
    return false
  end
  
  if elems.size <= 1
    return true
  end

  np = obj.object_parent
  if ! np
    return false
  end
  if elems[1].direct_parent
    return match_chain(np, elems[1..-1])
  else
    while np
      if match_chain(np, elems[1..-1])
        return true
      else
        np = np.object_parent
      end
    end
  end
  return false
end