class FilepathList

This is free software released into the public domain (CC0 license).

Constants

SEPARATOR

Public Class Methods

new(raw_entries = nil) click to toggle source
# File lib/filepath/filepathlist.rb, line 9
def initialize(raw_entries = nil)
        raw_entries ||= []
        @entries = raw_entries.map { |e| e.as_path }
end

Public Instance Methods

*(other_list) click to toggle source
# File lib/filepath/filepathlist.rb, line 49
def *(other_list)
        if !other_list.is_a? FilepathList
                other_list = FilepathList.new(Array(other_list))
        end
        other_entries = other_list.entries
        paths = @entries.product(other_entries).map { |p1, p2| p1 / p2 }
        return FilepathList.new(paths)
end
+(extra_entries) click to toggle source
# File lib/filepath/filepathlist.rb, line 35
def +(extra_entries)
        return FilepathList.new(@entries + extra_entries.to_a)
end
-(others) click to toggle source
# File lib/filepath/filepathlist.rb, line 39
def -(others)
        remaining_entries = @entries - others.as_path_list.to_a

        return FilepathList.new(remaining_entries)
end
/(extra_path) click to toggle source
# File lib/filepath/filepathlist.rb, line 31
def /(extra_path)
        return self.map { |path| path / extra_path }
end
<<(extra_path) click to toggle source
# File lib/filepath/filepathlist.rb, line 45
def <<(extra_path)
        return FilepathList.new(@entries + [extra_path.as_path])
end
==(other) click to toggle source
# File lib/filepath/filepathlist.rb, line 101
def ==(other)
        @entries == other.as_path_list.to_a
end
as_path_list() click to toggle source

@return [FilepathList] the path list itself

# File lib/filepath/filepathlist.rb, line 83
def as_path_list
        self
end
directories() click to toggle source
# File lib/filepath/filepathlist.rb, line 27
def directories
        return select_entries(:directory)
end
files() click to toggle source
# File lib/filepath/filepathlist.rb, line 19
def files
        return select_entries(:file)
end
inspect() click to toggle source

@private

# File lib/filepath/filepathlist.rb, line 97
def inspect
        @entries.inspect
end
remove_common_segments() click to toggle source
# File lib/filepath/filepathlist.rb, line 58
def remove_common_segments
        all_segs = @entries.map(&:segments)
        max_length = all_segs.map(&:length).min

        idx_different = nil

        (0..max_length).each do |i|
                segment = all_segs.first[i]

                different = all_segs.any? { |segs| segs[i] != segment }
                if different
                        idx_different = i
                        break
                end
        end

        idx_different ||= max_length

        remaining_segs = all_segs.map { |segs| segs[idx_different..-1] }

        return FilepathList.new(remaining_segs)
end
select_entries(type) click to toggle source
# File lib/filepath/filepathlist.rb, line 14
def select_entries(type)
        raw_entries = @entries.delete_if { |e| !e.send(type.to_s + '?') }
        return FilepathList.new(raw_entries)
end
to_a() click to toggle source
# File lib/filepath/filepathlist.rb, line 87
def to_a
        @entries
end
to_s() click to toggle source
# File lib/filepath/filepathlist.rb, line 91
def to_s
        @to_s ||= @entries.map(&:to_str).join(SEPARATOR)
end