Class: Eco::API::Common::People::DefaultParsers::SelectParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/eco/api/common/people/default_parsers/select_parser.rb

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize

Constructor Details

This class inherits a constructor from Eco::API::Common::People::BaseParser

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/eco/api/common/people/default_parsers/select_parser.rb', line 8

def process
  @parsers.define_attribute(:select, dependencies: @options) do |parser|
    parser.def_parser  do |value, deps|
      options_hash = deps[:select_hashes][deps["attr"]]
      next value if !options_hash
      if value.is_a?(Array)
        value.map { |v| options_hash[v&.downcase.strip] || v }
      elsif value
        options_hash[value&.downcase.strip] || value
      end
    end.def_serializer do |value|
      value
    end
  end
end