Class: EML::ModelHash

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/eml/lib/model_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ModelHash

Returns a new instance of ModelHash.



14
15
16
17
# File 'lib/eml/lib/model_hash.rb', line 14

def initialize(model)
  @model = T.let(model, EML::Model)
  @hash = T.let({}, T::Hash[Symbol, T.untyped])
end

Class Method Details

.call(model) ⇒ Object



9
10
11
# File 'lib/eml/lib/model_hash.rb', line 9

def self.call(model)
  new(model).call
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
# File 'lib/eml/lib/model_hash.rb', line 20

def call
  @model.class.enumerate_fields do |_, local_name|
    value = @model.public_send(local_name)
    add_value(local_name, value)
  end

  @hash
end