Class: Regexgen::State
- Inherits:
-
Object
- Object
- Regexgen::State
- Defined in:
- lib/regexgen/state.rb
Instance Attribute Summary collapse
-
#accepting ⇒ Object
Returns the value of attribute accepting.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
-
#initialize ⇒ State
constructor
A new instance of State.
- #to_h ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #visit(visited = Set.new) ⇒ Object
Constructor Details
Instance Attribute Details
#accepting ⇒ Object
Returns the value of attribute accepting.
5 6 7 |
# File 'lib/regexgen/state.rb', line 5 def accepting @accepting end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
6 7 8 |
# File 'lib/regexgen/state.rb', line 6 def transitions @transitions end |
Instance Method Details
#to_h ⇒ Object
21 22 23 24 25 |
# File 'lib/regexgen/state.rb', line 21 def to_h @transitions.transform_values(&:to_h).tap do |h| h[''] = nil if @accepting end end |
#to_s ⇒ Object Also known as: inspect
27 28 29 30 |
# File 'lib/regexgen/state.rb', line 27 def to_s sigil = @accepting ? '*' : '' "#{sigil}#{to_h}" end |
#visit(visited = Set.new) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/regexgen/state.rb', line 13 def visit(visited = Set.new) return visited if visited.include?(self) visited.add(self) @transitions.each_value { |state| state.visit(visited) } visited end |