Class: MCollective::Matcher::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/matcher/scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Scanner

Returns a new instance of Scanner.



6
7
8
9
10
11
# File 'lib/mcollective/matcher/scanner.rb', line 6

def initialize(arguments)
  @token_index = 0
  @arguments = arguments.split("")
  @seperation_counter = 0
  @white_spaces = 0
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



4
5
6
# File 'lib/mcollective/matcher/scanner.rb', line 4

def arguments
  @arguments
end

#token_indexObject

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_tokenObject

Scans the input string and identifies single language tokens



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
# File 'lib/mcollective/matcher/scanner.rb', line 14

def get_token
  if @token_index >= @arguments.size
    return nil
  end

  case @arguments[@token_index]
  when "("
    return "(", "("

  when ")"
    return ")", ")"

  when "n"
    if (@arguments[@token_index + 1] == "o") && (@arguments[@token_index + 2] == "t") && ((@arguments[@token_index + 3] == " ") || (@arguments[@token_index + 3] == "("))
      @token_index += 2
      return "not", "not"
    else
      gen_statement
    end

  when "!"
    return "not", "not"

  when "a"
    if (@arguments[@token_index + 1] == "n") && (@arguments[@token_index + 2] == "d") && ((@arguments[@token_index + 3] == " ") || (@arguments[@token_index + 3] == "("))
      @token_index += 2
      return "and", "and"
    else
      gen_statement
    end

  when "o"
    if (@arguments[@token_index + 1] == "r") && ((@arguments[@token_index + 2] == " ") || (@arguments[@token_index + 2] == "("))
      @token_index += 1
      return "or", "or"
    else
      gen_statement
    end

  when " "
    return " ", " "

  else
    gen_statement
  end
end