Class: Delfos::FileSystem::DistanceCalculation::TraversalPathCalculator
- Inherits:
-
Object
- Object
- Delfos::FileSystem::DistanceCalculation::TraversalPathCalculator
- Defined in:
- lib/delfos/file_system/distance_calculation.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#path_a ⇒ Object
readonly
Returns the value of attribute path_a.
-
#path_b ⇒ Object
readonly
Returns the value of attribute path_b.
Instance Method Summary collapse
- #full(start, traversal) ⇒ Object
-
#initialize(path_a, path_b) ⇒ TraversalPathCalculator
constructor
A new instance of TraversalPathCalculator.
- #path ⇒ Object
- #result ⇒ Object
- #same_directory? ⇒ Boolean
- #traversal ⇒ Object
Constructor Details
#initialize(path_a, path_b) ⇒ TraversalPathCalculator
Returns a new instance of TraversalPathCalculator.
52 53 54 55 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 52 def initialize(path_a, path_b) @path_a = path_a @path_b = path_b end |
Instance Attribute Details
#path_a ⇒ Object (readonly)
Returns the value of attribute path_a.
50 51 52 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 50 def path_a @path_a end |
#path_b ⇒ Object (readonly)
Returns the value of attribute path_b.
50 51 52 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 50 def path_b @path_b end |
Instance Method Details
#full(start, traversal) ⇒ Object
82 83 84 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 82 def full(start, traversal) start.realpath + Pathname.new(traversal) end |
#path ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 57 def path return [path_a, path_b] if same_directory? current_path = path_a traversal.descend do |p| current_path = full(path_a, p) result.process(current_path) end result end |
#result ⇒ Object
74 75 76 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 74 def result @result ||= Result.new([path_a]) end |
#same_directory? ⇒ Boolean
70 71 72 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 70 def same_directory? path_a.dirname == path_b.dirname end |
#traversal ⇒ Object
78 79 80 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 78 def traversal path_b.relative_path_from(path_a) end |