Class: Nginxtra::ConfigConverter::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/nginxtra/config_converter.rb

Constant Summary collapse

KEYWORDS =
["break", "if", "return"].freeze
TERMINAL_CHARACTERS =
["{", "}", ";"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Token

Returns a new instance of Token.



121
122
123
124
125
# File 'lib/nginxtra/config_converter.rb', line 121

def initialize(value = nil)
  @instance = true if value
  @value = value || ""
  @ready = false
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



119
120
121
# File 'lib/nginxtra/config_converter.rb', line 119

def value
  @value
end

Instance Method Details

#<<(c) ⇒ Object



162
163
164
165
166
# File 'lib/nginxtra/config_converter.rb', line 162

def <<(c)
  return space! if c =~ /\s/
  return terminal_character!(c) if TERMINAL_CHARACTERS.include? c
  @value << c
end

#block_end?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/nginxtra/config_converter.rb', line 151

def block_end?
  @value == "}"
end

#block_start?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/nginxtra/config_converter.rb', line 147

def block_start?
  @value == "{"
end

#end?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/nginxtra/config_converter.rb', line 143

def end?
  @value == ";"
end

#if_end!Object



135
136
137
# File 'lib/nginxtra/config_converter.rb', line 135

def if_end!
  @value.gsub! /\)$/, ""
end

#if_start!Object



131
132
133
# File 'lib/nginxtra/config_converter.rb', line 131

def if_start!
  @value.gsub! /^\(/, ""
end

#instanceObject



155
156
157
158
159
160
# File 'lib/nginxtra/config_converter.rb', line 155

def instance
  raise Nginxtra::Error::ConvertFailed.new("Whoops!") unless ready?
  token = Nginxtra::ConfigConverter::Token.new @value
  reset!
  token
end

#is_if?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/nginxtra/config_converter.rb', line 127

def is_if?
  @value == "if"
end

#ready?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/nginxtra/config_converter.rb', line 168

def ready?
  @instance || @ready || terminal_character?
end

#terminal_character?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/nginxtra/config_converter.rb', line 139

def terminal_character?
  TERMINAL_CHARACTERS.include? @value
end

#to_line_startObject



172
173
174
175
176
177
178
# File 'lib/nginxtra/config_converter.rb', line 172

def to_line_start
  if KEYWORDS.include? @value
    "_#{@value}"
  else
    @value
  end
end

#to_sObject



180
181
182
183
184
185
186
# File 'lib/nginxtra/config_converter.rb', line 180

def to_s
  if @value =~ /^\d+$/
    @value
  else
    %{"#{@value.gsub("\\") { "\\\\" }}"}
  end
end