Class: FidoMetadata::Coercer::MagicNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/fido_metadata/coercer/magic_number.rb

Instance Method Summary collapse

Constructor Details

#initialize(mapping, array: false) ⇒ MagicNumber

Returns a new instance of MagicNumber.



6
7
8
9
# File 'lib/fido_metadata/coercer/magic_number.rb', line 6

def initialize(mapping, array: false)
  @mapping = mapping
  @array = array
end

Instance Method Details

#coerce(values) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fido_metadata/coercer/magic_number.rb', line 11

def coerce(values)
  if @array
    return values unless values.all? { |value| value.is_a?(Integer) }

    values.map { |value| @mapping[value] }.compact
  else
    return values unless values.is_a?(Integer)

    @mapping[values]
  end
end