Class: Warp::Dir::Point

Inherits:
Object show all
Defined in:
lib/warp/dir/point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, full_path) ⇒ Point

Returns a new instance of Point.



8
9
10
11
12
13
# File 'lib/warp/dir/point.rb', line 8

def initialize(name, full_path)
  raise ArgumentError.new ':name is required' if name.nil?
  raise ArgumentError.new ':full_path is required' if full_path.nil?
  @full_path = Warp::Dir.absolute full_path
  @name      = name.to_sym
end

Instance Attribute Details

#full_pathObject

Returns the value of attribute full_path.



6
7
8
# File 'lib/warp/dir/point.rb', line 6

def full_path
  @full_path
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/warp/dir/point.rb', line 6

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/warp/dir/point.rb', line 39

def <=>(other)
  name <=> other.name
end

#absolute_pathObject



15
16
17
# File 'lib/warp/dir/point.rb', line 15

def absolute_path
  full_path
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/warp/dir/point.rb', line 43

def eql?(another)
  return false unless another.is_a?(Warp::Dir::Point)
  %i(name full_path).each do |attribute|
    return false unless send(attribute) == another.send(attribute)
  end
  true
end

#hashObject



35
36
37
# File 'lib/warp/dir/point.rb', line 35

def hash
  Digest::SHA1.base64digest("#{full_path.hash}#{name.hash}").hash
end

#inspectObject



27
28
29
# File 'lib/warp/dir/point.rb', line 27

def inspect
  sprintf("(#{object_id})[name: '%s', path: '%s']", name, relative_path)
end

#pathObject



23
24
25
# File 'lib/warp/dir/point.rb', line 23

def path
  absolute_path
end

#relative_pathObject



19
20
21
# File 'lib/warp/dir/point.rb', line 19

def relative_path
  Warp::Dir.relative full_path
end

#to_s(width = 0) ⇒ Object



31
32
33
# File 'lib/warp/dir/point.rb', line 31

def to_s(width = 0)
  sprintf("%#{width}s  ->  %s", name, relative_path)
end