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:



264
265
266
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 264

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

Instance Method Details

#<<(value) ⇒ Object

:nodoc:



268
269
270
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 268

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

#assert_emptyObject

:nodoc:

Raises:



272
273
274
275
276
277
278
279
280
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 272

def assert_empty # :nodoc:
  return if @values.empty?

  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

#create_optionalsObject

:nodoc:



306
307
308
309
310
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 306

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:



292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 292

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:



282
283
284
285
286
287
288
289
290
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 282

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:

Raises:



312
313
314
315
316
317
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 312

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