Sha256: e0c3563b178c7e6a57d15a0a2262ce724e25b9a7460189a1868df2ff920605a3

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

Contents

class PSD
  module Node
    module Search
      # Searches the tree structure for a node at the given path. The path is
      # defined by the layer/folder names. Because the PSD format does not
      # require unique layer/folder names, we always return an array of all
      # found nodes.
      def children_at_path(path, opts={})
        path = path.split('/').delete_if { |p| p == "" } unless path.is_a?(Array)

        path = path.dup
        query = path.shift
        matches = children.select do |c|
          if opts[:case_sensitive]
            c.name == query
          else
            c.name.downcase == query.downcase
          end
        end

        if path.length == 0
          return matches
        else
          return matches.map { |m| m.children_at_path(path.dup, opts) }.flatten
        end
      end
      alias :children_with_path :children_at_path
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
psd-3.2.4 lib/psd/nodes/search.rb
psd-3.2.3 lib/psd/nodes/search.rb
psd-3.2.2 lib/psd/nodes/search.rb
psd-3.2.1 lib/psd/nodes/search.rb
psd-3.2.0 lib/psd/nodes/search.rb