Class: LingutestClient::Base
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- LingutestClient::Base
- Extended by:
- Forwardable
- Defined in:
- lib/lingutest_client/base.rb
Direct Known Subclasses
Candidate, CandidateList, Exam, ExamList, Examination, ExaminationList
Instance Method Summary collapse
-
#to_hash(object = self, type = self.class) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Instance Method Details
#to_hash(object = self, type = self.class) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lingutest_client/base.rb', line 9 def to_hash(object = self, type = self.class) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength type.schema.each_with_object({}) do |key, res| name = key.name attr = key.type if array?(attr) values = ::Array.wrap(object.public_send(name)) res[name] = values.map do |value_item| serialize(value_item, attr.member) end elsif bool?(attr) value = object.public_send("#{name}?") res[name] = value else value = object.public_send(name) res[name] = serialize(value, attr) end end end |