Module: HotelBeds::Parser::InstanceMethods

Defined in:
lib/hotel_beds/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



77
78
79
80
81
82
# File 'lib/hotel_beds/parser.rb', line 77

def self.included(base)
  base.class_eval do
    attr_accessor :doc
    private :doc=
  end
end

Instance Method Details

#initialize(doc) ⇒ Object



84
85
86
87
# File 'lib/hotel_beds/parser.rb', line 84

def initialize(doc)
  self.doc = doc
  freeze
end

#to_hObject

parses the document into a hash of attributes



90
91
92
93
94
# File 'lib/hotel_beds/parser.rb', line 90

def to_h
  self.class.attributes.inject(Hash.new) do |result, attribute|
    result.merge(attribute.name => attribute.retrieve(doc))
  end
end

#to_model(klass = self.class.default_model_class) ⇒ Object

parses the document into a HotelBeds::Model instance



97
98
99
# File 'lib/hotel_beds/parser.rb', line 97

def to_model(klass = self.class.default_model_class)
  klass.new(to_h)
end