Class | YAML::YPath |
In: |
lib/yaml/ypath.rb
|
Parent: | Object |
flags | [RW] | |
predicates | [RW] | |
segments | [RW] |
# File lib/yaml/ypath.rb, line 25 25: def YPath.each_path( str ) 26: # 27: # Find choices 28: # 29: paths = [] 30: str = "(#{ str })" 31: while str.sub!( /\(([^()]+)\)/, "\n#{ paths.length }\n" ) 32: paths.push $1.split( '|' ) 33: end 34: 35: # 36: # Construct all possible paths 37: # 38: all = [ str ] 39: ( paths.length - 1 ).downto( 0 ) do |i| 40: all = all.collect do |a| 41: paths[i].collect do |p| 42: a.gsub( /\n#{ i }\n/, p ) 43: end 44: end.flatten.uniq 45: end 46: all.collect do |path| 47: yield YPath.new( path ) 48: end 49: end
# File lib/yaml/ypath.rb, line 9 9: def initialize( str ) 10: @segments = [] 11: @predicates = [] 12: @flags = nil 13: while str =~ /^\/?(\/|[^\/\[]+)(?:\[([^\]]+)\])?/ 14: @segments.push $1 15: @predicates.push $2 16: str = $' 17: end 18: unless str.to_s.empty? 19: @segments += str.split( "/" ) 20: end 21: if @segments.length == 0 22: @segments.push "." 23: end 24: end