Class: Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/cofgratx/cfg/terminal.rb

Direct Known Subclasses

Repetition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param) ⇒ Terminal

Returns a new instance of Terminal.



4
5
6
7
8
9
10
11
12
13
# File 'lib/cofgratx/cfg/terminal.rb', line 4

def initialize param
  unless %w{Regexp String}.include? param.class.name
    raise ArgumentError.new("expected Regular Expression or String; got #{param.class.name}")
  end
  param = param.class == String ?
            Regexp.escape(param) :
            param.source

  @terminal = Regexp.compile "^(" + param +")"
end

Instance Attribute Details

#terminalObject

Returns the value of attribute terminal.



2
3
4
# File 'lib/cofgratx/cfg/terminal.rb', line 2

def terminal
  @terminal
end

Instance Method Details

#extract(string) ⇒ Object



19
20
21
22
23
# File 'lib/cofgratx/cfg/terminal.rb', line 19

def extract string
  return [nil, string] unless @terminal =~ string
  terminal_match = $1
  [ $1, string[terminal_match.length..-1] ]
end

#match?(string) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/cofgratx/cfg/terminal.rb', line 15

def match? string
  (@terminal =~ string) == 0
end