Class: Gillbus::V2::Structs::Base
- Inherits:
-
Object
- Object
- Gillbus::V2::Structs::Base
- Defined in:
- lib/gillbus/v2/structs/base.rb
Direct Known Subclasses
AccessToken, Carrier, Location, LocationAdditionalField, LocationSubType, LocationType, Pagination, Point, RefundConditions, RoutePoint, Seat, Segment, SegmentOptions, SegmentPrice, SegmentSeatMap, SegmentTariff, Trip, Vehicle
Defined Under Namespace
Classes: Enum
Instance Attribute Summary collapse
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Class Method Summary collapse
- .field(name, type, from: name.to_s, default: nil, enrich_with: nil) ⇒ Object
- .from_raw_data(raw_data) ⇒ Object
Instance Method Summary collapse
-
#initialize(raw_data:, **fields) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(raw_data:, **fields) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 |
# File 'lib/gillbus/v2/structs/base.rb', line 13 def initialize(raw_data:, **fields) @raw_data = raw_data fields.each do |field_name, field_value| instance_variable_set(:"@#{field_name}", field_value) end end |
Instance Attribute Details
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
4 5 6 |
# File 'lib/gillbus/v2/structs/base.rb', line 4 def raw_data @raw_data end |
Class Method Details
.field(name, type, from: name.to_s, default: nil, enrich_with: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gillbus/v2/structs/base.rb', line 20 def self.field(name, type, from: name.to_s, default: nil, enrich_with: nil) attr_reader name @fields_settings ||= [] @fields_settings << { name: name, type: type, from: from, default: default, enrich_with: enrich_with, } end |
.from_raw_data(raw_data) ⇒ Object
32 33 34 35 |
# File 'lib/gillbus/v2/structs/base.rb', line 32 def self.from_raw_data(raw_data) fields = Parser.new.parse_fields(raw_data, @fields_settings) new(raw_data: raw_data, **fields) end |