Class: Format::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/src/format/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(yml, modifiers) ⇒ Formatter

Returns a new instance of Formatter.



8
9
10
11
# File 'lib/src/format/formatter.rb', line 8

def initialize(yml, modifiers)
  @mapper = Format::Mapper.new(yml)
  @modifier = Format::Modifier.new(yml, modifiers)
end

Instance Method Details

#format_value(value, props) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/src/format/formatter.rb', line 13

def format_value(value, props)
  modifier_prop, mapper_prop = props.values_at(:modifier, :mapper)

  value
    .then { |it| modifier.apply(it, modifier_prop) }
    .then { |it| nullify_empty_value(it) }
    .then { |it| mapper.apply(it, mapper_prop) }
end