class Delfos::FileSystem::Relation
Attributes
finish_path[R]
start_path[R]
Public Class Methods
new(start_path, finish_path)
click to toggle source
# File lib/delfos/file_system/relation.rb, line 7 def initialize(start_path, finish_path) @start_path = start_path @finish_path = finish_path end
Public Instance Methods
distance()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 20 def distance return traversed_files.length if both_files? return traversed_directories.length if both_directories? traversed_files.length + traversed_directories.length end
other_directories()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 16 def other_directories RelatedPaths.new(start_path).directories end
other_files()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 12 def other_files RelatedPaths.new(start_path).files end
possible_length()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 27 def possible_length other_files.length + other_directories.length end
subset_to_traverse(collection:, start:, finish:, start_at_end: true)
click to toggle source
# File lib/delfos/file_system/relation.rb, line 49 def subset_to_traverse(collection:, start:, finish:, start_at_end: true) start_index, finish_index = indexes_from(collection, start, finish, start_at_end) Array collection[start_index..finish_index] end
traversed_directories()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 40 def traversed_directories start_at_end = (start_path.file? && finish_path.directory?) || (start_path.directory? && finish_path.file?) subset_to_traverse(collection: other_directories, start: start_path, finish: finish_path, start_at_end: start_at_end) end
traversed_files()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 31 def traversed_files start_at_end = (start_path.file? && finish_path.directory?) subset_to_traverse(collection: other_files, start: start_path, finish: finish_path, start_at_end: start_at_end) end
Private Instance Methods
both_directories?()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 61 def both_directories? start_path.directory? && finish_path.directory? end
both_files?()
click to toggle source
# File lib/delfos/file_system/relation.rb, line 57 def both_files? start_path.file? && finish_path.file? end
index_from(collection, value, reverse: false, start_at_end: false)
click to toggle source
# File lib/delfos/file_system/relation.rb, line 76 def index_from(collection, value, reverse: false, start_at_end: false) index = collection.index value if index.nil? index = start_at_end && !reverse ? collection.length - 1 : 0 end index end
indexes_from(collection, start, finish, start_at_end)
click to toggle source
# File lib/delfos/file_system/relation.rb, line 65 def indexes_from(collection, start, finish, start_at_end) start_index = index_from(collection, start, start_at_end: start_at_end) finish_index = index_from(collection, finish, start_at_end: start_at_end, reverse: true) if start_index.zero? && finish_index.zero? finish_index = collection.length - 1 end [start_index, finish_index].sort end