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:


261
262
263
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 261

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

Instance Method Details

#<<(value_) ⇒ Object

:nodoc:


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

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

#assert_emptyObject

:nodoc:


269
270
271
272
273
274
275
276
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 269

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

#create_optionalsObject

:nodoc:


302
303
304
305
306
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 302

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:


288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 288

def find_all(klass_)  # :nodoc:
  results_ = []
  nvalues_ = []
  @values.each do |val_|
    if val_.kind_of?(klass_)
      results_ << val_
    else
      nvalues_ << val_
    end
  end
  @values = nvalues_
  results_
end

#find_first(klass_) ⇒ Object

:nodoc:


278
279
280
281
282
283
284
285
286
# File 'lib/rgeo/coord_sys/cs/wkt_parser.rb', line 278

def find_first(klass_)  # :nodoc:
  @values.each_with_index do |val_, index_|
    if val_.kind_of?(klass_)
      @values.slice!(index_)
      return val_
    end
  end
  nil
end

#shift(klass_ = nil) ⇒ Object

:nodoc:


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

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