Class: Terminal
- Inherits:
-
Object
- Object
- Terminal
- Defined in:
- lib/cofgratx/cfg/terminal.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#terminal ⇒ Object
Returns the value of attribute terminal.
Instance Method Summary collapse
- #extract(string) ⇒ Object
-
#initialize(param) ⇒ Terminal
constructor
A new instance of Terminal.
- #match?(string) ⇒ Boolean
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
#terminal ⇒ Object
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
15 16 17 |
# File 'lib/cofgratx/cfg/terminal.rb', line 15 def match? string (@terminal =~ string) == 0 end |