Class: Teeth::ScannerDefinition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, regex, opts = {}) ⇒ ScannerDefinition

Returns a new instance of ScannerDefinition.



14
15
16
17
18
19
20
# File 'lib/teeth/scanner_definition.rb', line 14

def initialize(name, regex, opts={})
  if regex.kind_of?(Hash)
    regex, opts = nil, regex
  end
  @name, @regex, @start_condition = name, regex, opts[:start_condition]
  assert_valid_argument_combination
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/teeth/scanner_definition.rb', line 12

def name
  @name
end

#regexObject (readonly)

Returns the value of attribute regex.



12
13
14
# File 'lib/teeth/scanner_definition.rb', line 12

def regex
  @regex
end

Instance Method Details

#regex_to_sObject



26
27
28
29
30
31
32
# File 'lib/teeth/scanner_definition.rb', line 26

def regex_to_s
  unless @regex.to_s == ""
    " " + @regex.to_s
  else
    ""
  end
end

#scanner_codeObject



22
23
24
# File 'lib/teeth/scanner_definition.rb', line 22

def scanner_code
  start_condition_string + @name.to_s + regex_to_s
end

#start_condition_stringObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/teeth/scanner_definition.rb', line 34

def start_condition_string
  case @start_condition.to_s
  when /^inc/
    "%s "
  when /^exc/
    "%x "
  else
    ""
  end
end