Module: Gillbus::Fields
- Included in:
- BaseResponse, BusPhoto, BuyBooking::Response::TicketConfirmation, BuyTickets::Response::TicketConfirmation, CancelOrder::Response::OrderCancel, Carrier, Commission, GetAllCities::City, GetBusImage::Image, GetCities::City, GetCountries::Country, Item, Luggage, NearbyCitiesTrip, Point, ReturnCause, ReturnPosition::Response::ReturnPosition, Seat, Segment, Tariff, Tariff::ReturnCause, Ticket, TicketsOption, TimetableSegment, TimetableTrip, Trip, TripOptions, TripService
- Defined in:
- lib/gillbus/helpers/fields.rb
Overview
Gives a bunch of class methods to parse gillbus responses hash and define accessors
Warning:
resulting definitions won't work properly in subclass
Usage:
class MyClass
extend Gillbus::Fields
field :foo, :date
end
MyClass.parse(hash)
Instance Method Summary collapse
- #parse(doc, instance: new, parent: nil, options: {}) ⇒ Object
- #parser(&definition) ⇒ Object
- #parser_class ⇒ Object
Instance Method Details
#parse(doc, instance: new, parent: nil, options: {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gillbus/helpers/fields.rb', line 24 def parse(doc, instance: new, parent: nil, options: {}) instance ||= new parser_class.new( doc: doc, instance: instance, fields: field_definitions, parent: parent, options: , ).parse instance end |
#parser(&definition) ⇒ Object
36 37 38 |
# File 'lib/gillbus/helpers/fields.rb', line 36 def parser(&definition) @parser_class = Class.new(parser_class, &definition) end |