Class: Gillbus::TripService

Inherits:
Object
  • Object
show all
Extended by:
Fields
Includes:
UpdateAttrs
Defined in:
lib/gillbus/structs/trip_service.rb

Class Method Summary collapse

Methods included from Fields

parse, parser, parser_class

Methods included from UpdateAttrs

#initialize, #update_attrs

Class Method Details

.parse(doc, instance: nil, parent: nil, options: {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gillbus/structs/trip_service.rb', line 12

def self.parse(doc, instance: nil, parent: nil, options: {})
  instance = new
  if doc.is_a?(Array)
    raise ArgumentError, "Unable to parse TripService: #{doc.inspect}" unless doc.size == 2
    instance.id = doc.first.fetch('ID').to_i
    instance.name = doc.last
  elsif doc.is_a?(Hash) #legacy data made with MultiXML
    instance.id = doc.fetch('ID')
    instance.name = doc.fetch('__content__')
  else
    raise ArgumentError, "Unable to parse TripService: #{doc.inspect}"
  end
  instance
end