Class: Syck::YPath
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#predicates ⇒ Object
Returns the value of attribute predicates.
-
#segments ⇒ Object
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str) ⇒ YPath
constructor
A new instance of YPath.
Constructor Details
#initialize(str) ⇒ YPath
Returns a new instance of YPath.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/syck/ypath.rb', line 11 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
#flags ⇒ Object
Returns the value of attribute flags
10 11 12 |
# File 'lib/syck/ypath.rb', line 10 def flags @flags end |
#predicates ⇒ Object
Returns the value of attribute predicates
10 11 12 |
# File 'lib/syck/ypath.rb', line 10 def predicates @predicates end |
#segments ⇒ Object
Returns the value of attribute segments
10 11 12 |
# File 'lib/syck/ypath.rb', line 10 def segments @segments end |
Class Method Details
.each_path(str) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/syck/ypath.rb', line 27 def self.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 |