Class: PathElement
Instance Attribute Summary collapse
-
#cost_to ⇒ Object
Returns the value of attribute cost_to.
-
#dist_from ⇒ Object
Returns the value of attribute dist_from.
-
#location ⇒ Object
Returns the value of attribute location.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(location = nil, parent = nil) ⇒ PathElement
constructor
A new instance of PathElement.
- #reset_rating ⇒ Object
- #to_s ⇒ Object
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_to ⇒ Object
Returns the value of attribute cost_to.
70 71 72 |
# File 'lib/polaris.rb', line 70 def cost_to @cost_to end |
#dist_from ⇒ Object
Returns the value of attribute dist_from.
70 71 72 |
# File 'lib/polaris.rb', line 70 def dist_from @dist_from end |
#location ⇒ Object
Returns the value of attribute location.
69 70 71 |
# File 'lib/polaris.rb', line 69 def location @location end |
#parent ⇒ Object
Returns the value of attribute parent.
69 70 71 |
# File 'lib/polaris.rb', line 69 def parent @parent end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating.
70 71 72 |
# File 'lib/polaris.rb', line 70 def @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. < b. return -1 elsif a. > b. 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_rating ⇒ Object
89 90 91 |
# File 'lib/polaris.rb', line 89 def @rating = @cost_to + @dist_from end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/polaris.rb', line 93 def to_s "#{@location} at cost of #{@cost_to} and rating of #{@rating}" end |