Sha256: 0a8871605ba311bd7dc8d1dacbb61c831b0da793d4b064928db017bd38d87eae

Contents?: true

Size: 816 Bytes

Versions: 13

Compression:

Stored size: 816 Bytes

Contents

class PSD
  class 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)

        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, opts) }.flatten
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
psd-1.2.2 lib/psd/nodes/search.rb
psd-1.2.1 lib/psd/nodes/search.rb
psd-1.2.0 lib/psd/nodes/search.rb
psd-1.1.1 lib/psd/nodes/search.rb
psd-1.1.0 lib/psd/nodes/search.rb
psd-1.0.0 lib/psd/nodes/search.rb
psd-0.4.2 lib/psd/nodes/search.rb
psd-0.4.1 lib/psd/nodes/search.rb
psd-0.4.0 lib/psd/nodes/search.rb
psd-0.3.5 lib/psd/nodes/search.rb
psd-0.3.4 lib/psd/nodes/search.rb
psd-0.3.3 lib/psd/nodes/search.rb
psd-0.3.2 lib/psd/nodes/search.rb