Class: TicketObject

Inherits:
Object
  • Object
show all
Defined in:
lib/ttr/objects/ticket.rb

Overview

Copyright © 2011 Jesse Sielaff

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points, city_objs) ⇒ TicketObject

Returns a new instance of TicketObject.



7
8
9
10
# File 'lib/ttr/objects/ticket.rb', line 7

def initialize (points, city_objs)
  @city_objs = city_objs
  @points = points
end

Instance Attribute Details

#city_objsObject (readonly)

Returns the value of attribute city_objs.



12
13
14
# File 'lib/ttr/objects/ticket.rb', line 12

def city_objs
  @city_objs
end

#pointsObject (readonly)

Returns the value of attribute points.



12
13
14
# File 'lib/ttr/objects/ticket.rb', line 12

def points
  @points
end

Instance Method Details

#completed?(route_objs) ⇒ Boolean

Returns true if the Ticket is completed by any combination of the given Routes, false otherwise.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/ttr/objects/ticket.rb', line 17

def completed? (route_objs)
  c1, c2 = city_objs
  return false unless route_objs.any? {|obj| obj.into?(c1) }
  return false unless route_objs.any? {|obj| obj.into?(c2) }
  
  c1.connected_using?(c2, route_objs)
end