Class: Delfos::FileSystem::Relation
- Inherits:
-
Object
- Object
- Delfos::FileSystem::Relation
- Defined in:
- lib/delfos/file_system/relation.rb
Direct Known Subclasses
Defined Under Namespace
Classes: RelatedPaths
Instance Attribute Summary collapse
-
#finish_path ⇒ Object
readonly
Returns the value of attribute finish_path.
-
#start_path ⇒ Object
readonly
Returns the value of attribute start_path.
Instance Method Summary collapse
- #distance ⇒ Object
-
#initialize(start_path, finish_path) ⇒ Relation
constructor
A new instance of Relation.
- #other_directories ⇒ Object
- #other_files ⇒ Object
- #possible_length ⇒ Object
- #subset_to_traverse(collection:, start:, finish:, start_at_end: true) ⇒ Object
- #traversed_directories ⇒ Object
- #traversed_files ⇒ Object
Constructor Details
#initialize(start_path, finish_path) ⇒ Relation
Returns a new instance of Relation.
7 8 9 10 |
# File 'lib/delfos/file_system/relation.rb', line 7 def initialize(start_path, finish_path) @start_path = start_path @finish_path = finish_path end |
Instance Attribute Details
#finish_path ⇒ Object (readonly)
Returns the value of attribute finish_path.
5 6 7 |
# File 'lib/delfos/file_system/relation.rb', line 5 def finish_path @finish_path end |
#start_path ⇒ Object (readonly)
Returns the value of attribute start_path.
5 6 7 |
# File 'lib/delfos/file_system/relation.rb', line 5 def start_path @start_path end |
Instance Method Details
#distance ⇒ Object
20 21 22 23 24 25 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/delfos/file_system/relation.rb', line 16 def other_directories .new(start_path).directories end |
#other_files ⇒ Object
12 13 14 |
# File 'lib/delfos/file_system/relation.rb', line 12 def other_files .new(start_path).files end |
#possible_length ⇒ Object
27 28 29 |
# 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) ⇒ Object
49 50 51 52 53 |
# 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 ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 |