Class: MCollective::Matcher::Scanner
- Inherits:
-
Object
- Object
- MCollective::Matcher::Scanner
- Defined in:
- lib/mcollective/matcher/scanner.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#token_index ⇒ Object
Returns the value of attribute token_index.
Instance Method Summary collapse
-
#get_token ⇒ Object
Scans the input string and identifies single language tokens.
-
#initialize(arguments) ⇒ Scanner
constructor
A new instance of Scanner.
Constructor Details
#initialize(arguments) ⇒ Scanner
Returns a new instance of Scanner.
6 7 8 9 |
# File 'lib/mcollective/matcher/scanner.rb', line 6 def initialize(arguments) @token_index = 0 @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/mcollective/matcher/scanner.rb', line 4 def arguments @arguments end |
#token_index ⇒ Object
Returns the value of attribute token_index.
4 5 6 |
# File 'lib/mcollective/matcher/scanner.rb', line 4 def token_index @token_index end |
Instance Method Details
#get_token ⇒ Object
Scans the input string and identifies single language tokens
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mcollective/matcher/scanner.rb', line 12 def get_token if @token_index >= @arguments.size return nil end begin case @arguments.split("")[@token_index] when "(" return "(", "(" when ")" return ")", ")" when "n" if (@arguments.split("")[@token_index + 1] == "o") && (@arguments.split("")[@token_index + 2] == "t") && ((@arguments.split("")[@token_index + 3] == " ") || (@arguments.split("")[@token_index + 3] == "(")) @token_index += 2 return "not", "not" else gen_statement end when "!" return "not", "not" when "a" if (@arguments.split("")[@token_index + 1] == "n") && (@arguments.split("")[@token_index + 2] == "d") && ((@arguments.split("")[@token_index + 3] == " ") || (@arguments.split("")[@token_index + 3] == "(")) @token_index += 2 return "and", "and" else gen_statement end when "o" if (@arguments.split("")[@token_index + 1] == "r") && ((@arguments.split("")[@token_index + 2] == " ") || (@arguments.split("")[@token_index + 2] == "(")) @token_index += 1 return "or", "or" else gen_statement end when " " return " ", " " else gen_statement end end rescue NoMethodError => e pp e raise "Cannot end statement with 'and', 'or', 'not'" end |