Sha256: 501e7ed0fb798d19fea26f117e65a79b1d8929958be997d5bb6190413255f065

Contents?: true

Size: 668 Bytes

Versions: 13

Compression:

Stored size: 668 Bytes

Contents

# frozen_string_literal: true

module DevSuite
  module DirectoryTree
    module Node
      class Directory < Base
        attr_reader :children

        def initialize(name)
          super
          @children = []
        end

        def directory?
          true
        end

        def add_child(node)
          @children << node
          sort_children!
        end

        private

        def sort_children!
          @children.sort_by! do |node|
            [
              node.hidden? ? 1 : 0, # Hidden nodes should be at the end
              node.name.downcase,   # Alphabetical order
            ]
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dev_suite-0.2.13 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.12 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.11 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.10 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.9 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.8 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.7 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.6 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.5 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.4 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.3 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.2 lib/dev_suite/directory_tree/node/directory.rb
dev_suite-0.2.1 lib/dev_suite/directory_tree/node/directory.rb