Class: RGeo::CoordSys::CS::WKTParser::ArgumentList

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/coord_sys/cs/wkt_parser.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeArgumentList

:nodoc:


213
214
215
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 213

def initialize # :nodoc:
  @values = []
end

Instance Method Details

#<<(value) ⇒ Object

:nodoc:


217
218
219
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 217

def <<(value) # :nodoc:
  @values << value
end

#assert_emptyObject

:nodoc:


221
222
223
224
225
226
227
228
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 221

def assert_empty # :nodoc:
  if @values.size > 0
    names = @values.map do |val|
      val.is_a?(Base) ? val.wkt_typename : val.inspect
    end
    raise Error::ParseError, "#{@values.size} unexpected arguments: #{names.join(', ')}"
  end
end

#create_optionalsObject

:nodoc:


254
255
256
257
258
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 254

def create_optionals # :nodoc:
  hash = {}
  find_all(ExtensionClause).each { |ec| hash[ec.key] = ec.value }
  (find_first(AuthorityClause) || [nil, nil]).to_a + [nil, nil, nil, hash]
end

#find_all(klass) ⇒ Object

:nodoc:


240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 240

def find_all(klass) # :nodoc:
  results = []
  nvalues = []
  @values.each do |val|
    if val.is_a?(klass)
      results << val
    else
      nvalues << val
    end
  end
  @values = nvalues
  results
end

#find_first(klass) ⇒ Object

:nodoc:


230
231
232
233
234
235
236
237
238
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 230

def find_first(klass) # :nodoc:
  @values.each_with_index do |val, index|
    if val.is_a?(klass)
      @values.slice!(index)
      return val
    end
  end
  nil
end

#shift(klass = nil) ⇒ Object

:nodoc:


260
261
262
263
264
265
266
267
268
269
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 260

def shift(klass = nil) # :nodoc:
  val = @values.shift
  unless val
    raise Error::ParseError, "No arguments left... expected #{klass}"
  end
  if klass && !val.is_a?(klass)
    raise Error::ParseError, "Expected #{klass} but got #{val.class}"
  end
  val
end