Class: PathElement

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/polaris.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = nil, parent = nil) ⇒ PathElement

Returns a new instance of PathElement.



71
72
73
74
75
76
77
# File 'lib/polaris.rb', line 71

def initialize(location=nil,parent=nil)
  @location = location
  @parent = parent
  @cost_to = 0
  @dist_from = 0
  @rating = 99_999
end

Instance Attribute Details

#cost_toObject

Returns the value of attribute cost_to.



70
71
72
# File 'lib/polaris.rb', line 70

def cost_to
  @cost_to
end

#dist_fromObject

Returns the value of attribute dist_from.



70
71
72
# File 'lib/polaris.rb', line 70

def dist_from
  @dist_from
end

#locationObject

Returns the value of attribute location.



69
70
71
# File 'lib/polaris.rb', line 69

def location
  @location
end

#parentObject

Returns the value of attribute parent.



69
70
71
# File 'lib/polaris.rb', line 69

def parent
  @parent
end

#ratingObject (readonly)

Returns the value of attribute rating.



70
71
72
# File 'lib/polaris.rb', line 70

def rating
  @rating
end

Instance Method Details

#<=>(b) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/polaris.rb', line 97

def <=>(b)
  a = self
  if a.rating < b.rating
    return -1
  elsif a.rating > b.rating
    return 1
  else
    0
  end
end

#==(other) ⇒ Object



108
109
110
111
# File 'lib/polaris.rb', line 108

def ==(other)
  return false if other.nil?
  @location == other.location
end

#reset_ratingObject



89
90
91
# File 'lib/polaris.rb', line 89

def reset_rating
  @rating = @cost_to + @dist_from
end

#to_sObject



93
94
95
# File 'lib/polaris.rb', line 93

def to_s
  "#{@location} at cost of #{@cost_to} and rating of #{@rating}"
end