Class: Gtfskit::Dataset::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gtfskit/dataset/base.rb

Direct Known Subclasses

Agency, Calendar, CalendarDate, Route, Stop, StopTime, Trip

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**fields) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gtfskit/dataset/base.rb', line 18

def initialize(**fields)
  _required_fields = required_fields

  fields.each do |field, value|
    _required_fields.delete(field)
    instance_variable_set("@#{field}", value)
  end

  if !_required_fields.empty?
    raise MissingRequiredFieldsError, "The required fields: #{_required_fields.join(", ")} were not passed as arguments to initialize", caller
  end
end

Class Method Details

.optional_fields(*fields) ⇒ Object



12
13
14
15
# File 'lib/gtfskit/dataset/base.rb', line 12

def optional_fields(*fields)
  @optional_fields = fields.to_set
  attr_reader *fields
end

.required_fields(*fields) ⇒ Object



7
8
9
10
# File 'lib/gtfskit/dataset/base.rb', line 7

def required_fields(*fields)
  @required_fields = fields.to_set
  attr_reader *fields
end

Instance Method Details

#optional_fieldsObject



35
36
37
# File 'lib/gtfskit/dataset/base.rb', line 35

def optional_fields
  self.class.instance_variable_get("@optional_fields").dup
end

#required_fieldsObject



31
32
33
# File 'lib/gtfskit/dataset/base.rb', line 31

def required_fields
  self.class.instance_variable_get("@required_fields").dup
end