Class: Kleene::State

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

Constant Summary collapse

@@next_id =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(final = false, error = false, id = nil) ⇒ State

Returns a new instance of State.



35
36
37
38
39
# File 'lib/kleene/kleene.rb', line 35

def initialize(final = false, error = false, id = nil)
  @final = final
  @error = error
  @id = id || State.next_id
end

Instance Attribute Details

#errorObject

: Bool



33
34
35
# File 'lib/kleene/kleene.rb', line 33

def error
  @error
end

#finalObject

: Bool



32
33
34
# File 'lib/kleene/kleene.rb', line 32

def final
  @final
end

#idObject (readonly)

: Int32



31
32
33
# File 'lib/kleene/kleene.rb', line 31

def id
  @id
end

Class Method Details

.new_error_state(final = false) ⇒ Object



27
28
29
# File 'lib/kleene/kleene.rb', line 27

def self.new_error_state(final = false)
  State.new(final, true)
end

.next_idObject



23
24
25
# File 'lib/kleene/kleene.rb', line 23

def self.next_id
  @@next_id += 1
end

Instance Method Details

#dupObject



51
52
53
# File 'lib/kleene/kleene.rb', line 51

def dup
  State.new(@final, @error, nil)
end

#error?Boolean

is this an error state?

Returns:

  • (Boolean)


42
43
44
# File 'lib/kleene/kleene.rb', line 42

def error?
  @error
end

#final?Boolean

is this a final state?

Returns:

  • (Boolean)


47
48
49
# File 'lib/kleene/kleene.rb', line 47

def final?
  @final
end

#to_sObject



55
56
57
# File 'lib/kleene/kleene.rb', line 55

def to_s
  "State{id: #{id}, final: #{final}, error: #{error}}"
end