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