Class: Ellington::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ellington/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, type, *states) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
9
# File 'lib/ellington/connection.rb', line 5

def initialize(line, type, *states)
  @line = line
  @type = type
  @states = Ellington::Target.new(*states)
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



3
4
5
# File 'lib/ellington/connection.rb', line 3

def line
  @line
end

#statesObject (readonly)

Returns the value of attribute states.



3
4
5
# File 'lib/ellington/connection.rb', line 3

def states
  @states
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/ellington/connection.rb', line 3

def type
  @type
end

Instance Method Details

#required?(passenger) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ellington/connection.rb', line 11

def required?(passenger)
  return false if line.boarded?(passenger)

  if type == :if_any
    return states.satisfied?(passenger) 
  end

  if type == :if_all
    return (passenger.state_history & states).length == states.length
  end

  false
end