Class: Delfos::FileSystem::DistanceCalculation
- Inherits:
-
Object
- Object
- Delfos::FileSystem::DistanceCalculation
- Defined in:
- lib/delfos/file_system/distance_calculation.rb
Defined Under Namespace
Classes: TraversalPathCalculator
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.
-
#traversal_a ⇒ Object
readonly
Returns the value of attribute traversal_a.
-
#traversal_b ⇒ Object
readonly
Returns the value of attribute traversal_b.
Instance Method Summary collapse
-
#initialize(path_a, path_b) ⇒ DistanceCalculation
constructor
A new instance of DistanceCalculation.
- #klass_for(a, b) ⇒ Object
- #sibling_directories(path) ⇒ Object
- #sum_possible_traversals ⇒ Object
- #sum_traversals ⇒ Object
- #traversal_path ⇒ Object
- #traversals ⇒ Object
Constructor Details
#initialize(path_a, path_b) ⇒ DistanceCalculation
Returns a new instance of DistanceCalculation.
10 11 12 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 10 def initialize(path_a, path_b) @path_a, @path_b = PathDetermination.for(path_a, path_b) end |
Instance Attribute Details
#path_a ⇒ Object (readonly)
Returns the value of attribute path_a.
8 9 10 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 8 def path_a @path_a end |
#path_b ⇒ Object (readonly)
Returns the value of attribute path_b.
8 9 10 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 8 def path_b @path_b end |
#traversal_a ⇒ Object (readonly)
Returns the value of attribute traversal_a.
14 15 16 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 14 def traversal_a @traversal_a end |
#traversal_b ⇒ Object (readonly)
Returns the value of attribute traversal_b.
14 15 16 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 14 def traversal_b @traversal_b end |
Instance Method Details
#klass_for(a, b) ⇒ Object
28 29 30 31 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 28 def klass_for(a, b) return ChildFile if b + ".." == a Relation end |
#sibling_directories(path) ⇒ Object
41 42 43 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 41 def sibling_directories(path) siblings(path).select { |f| File.directory?(f) } end |
#sum_possible_traversals ⇒ Object
37 38 39 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 37 def sum_possible_traversals traversals.inject(0) { |a, e| a + e.possible_length } end |
#sum_traversals ⇒ Object
33 34 35 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 33 def sum_traversals traversals.inject(0) { |a, e| a + e.distance } end |
#traversal_path ⇒ Object
45 46 47 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 45 def traversal_path TraversalPathCalculator.new(path_a, path_b).path end |
#traversals ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/delfos/file_system/distance_calculation.rb', line 16 def traversals result = [] path = traversal_path path.each_cons(2) do |start, finish| klass = klass_for(start, finish) result.push(klass.new(start, finish)) end result end |