Sha256: e55ea4c2c29c36203ebb4393c09cf41d7fba27547382c0d28cf40669f4b49cfc

Contents?: true

Size: 1.35 KB

Versions: 19

Compression:

Stored size: 1.35 KB

Contents

#
# YAML::YPath
#

warn "#{caller[0]}: YAML::YPath is deprecated" if $VERBOSE

module Syck

    class YPath
        attr_accessor :segments, :predicates, :flags
        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
        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
    end

end

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
syck-1.5.1.1 lib/syck/ypath.rb
syck-1.5.1 lib/syck/ypath.rb
syck-1.5.0 lib/syck/ypath.rb
syck-1.4.1 lib/syck/ypath.rb
syck-1.4.0 lib/syck/ypath.rb
syck-1.3.0 lib/syck/ypath.rb
syck-1.2.0 lib/syck/ypath.rb
syck-1.1.0 lib/syck/ypath.rb
syck-1.0.5 lib/syck/ypath.rb
syck-1.0.4 lib/syck/ypath.rb
syck-1.0.3 lib/syck/ypath.rb
rubysl-yaml-2.0.4 lib/syck/ypath.rb
rubysl-yaml-2.0.3 lib/syck/ypath.rb
rubysl-yaml-2.0.2 lib/syck/ypath.rb
rubysl-syck-2.0.2 lib/syck/ypath.rb
syck-1.0.1 lib/syck/ypath.rb
syck-1.0.0.4 lib/syck/ypath.rb
concordia-publishing-house-syck-1.0.0.4 lib/syck/ypath.rb
syck-1.0.0 lib/syck/ypath.rb