Class: Delfos::FileSystem::DistanceCalculation::TraversalPathCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/delfos/file_system/distance_calculation.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

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_aObject (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_bObject (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

#pathObject



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

#resultObject



74
75
76
# File 'lib/delfos/file_system/distance_calculation.rb', line 74

def result
  @result ||= Result.new([path_a])
end

#same_directory?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/delfos/file_system/distance_calculation.rb', line 70

def same_directory?
  path_a.dirname == path_b.dirname
end

#traversalObject



78
79
80
# File 'lib/delfos/file_system/distance_calculation.rb', line 78

def traversal
  path_b.relative_path_from(path_a)
end