Class: Pump

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

Overview

Pump Lemma It takes language as lambda function and a word as a string lang is a regular expression like a^b^ given as lambda function and set by user word is the word to check pumping length is the length of the string you want to pump return is_regular to tell if lang is regular and decomposition to show why

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lang:, length:) ⇒ Pump

Returns a new instance of Pump.



13
14
15
16
17
# File 'lib/pump.rb', line 13

def initialize(lang:, length:)
  @lang   = lang
  @length = length
  @word   = ''
end

Instance Attribute Details

#decompositionObject (readonly)

Returns the value of attribute decomposition.



11
12
13
# File 'lib/pump.rb', line 11

def decomposition
  @decomposition
end

#is_regularObject (readonly)

Returns the value of attribute is_regular.



11
12
13
# File 'lib/pump.rb', line 11

def is_regular
  @is_regular
end

#langObject

Returns the value of attribute lang.



10
11
12
# File 'lib/pump.rb', line 10

def lang
  @lang
end

#wordObject

Returns the value of attribute word.



10
11
12
# File 'lib/pump.rb', line 10

def word
  @word
end

Instance Method Details

#run(show_pros:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pump.rb', line 19

def run(show_pros:)
  _clear_old_run

  r, s, t = ''

  @word.length.times do |leng|
    r, s, t = _sigma_chars leng

    pump_up_down_res = _pump_up_down_res r, s, t, show_pros
    not_in_language  = pump_up_down_res.include? false

    @is_regular = false if not_in_language

    break if not_in_language
  end

  @decomposition = [r, s, t]
end