Class: YAML::YRegexPath

Inherits:
Object show all
Defined in:
lib/yaml_extensions/yregexpath.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ YRegexPath

Returns a new instance of YRegexPath.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/yaml_extensions/yregexpath.rb', line 14

def initialize ( str )
  raise ArgumentError, 'Argument must be a string' unless str.is_a?(String)
  @segments = []
  @wanted_node_index = nil
  @root = (str[0] == ?/)
  while str =~ /^(\/|#)?((?:(?:\\.)|[^\\=\/#])+)(?:=((?:(?:\\.)|[^\\\/#])*))?/
    if ($1 == "#")
      if (@wanted_node_index.nil?)
        @wanted_node_index = @segments.length
      else
        raise ArgumentError, 'More than a "#" given.'
      end
    end
    if ($3.nil?)
      @segments << Regexp.new($2)
    else
      @segments << [ Regexp.new($2), Regexp.new($3) ]
    end
    str = $'
  end
  @wanted_node_index = @segments.length if @wanted_node_index.nil?
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



12
13
14
# File 'lib/yaml_extensions/yregexpath.rb', line 12

def root
  @root
end

#segmentsObject (readonly)

Returns the value of attribute segments.



12
13
14
# File 'lib/yaml_extensions/yregexpath.rb', line 12

def segments
  @segments
end

#wanted_node_indexObject (readonly)

Returns the value of attribute wanted_node_index.



12
13
14
# File 'lib/yaml_extensions/yregexpath.rb', line 12

def wanted_node_index
  @wanted_node_index
end