Sha256: 2fd4015ac6dd2de4b40c6b20c677ac6672c7562b87f8b02853cddb52fa8fd88a
Contents?: true
Size: 667 Bytes
Versions: 5
Compression:
Stored size: 667 Bytes
Contents
require_relative "mapper" require_relative "modifier" module Format class Formatter def initialize(yml, modifiers) @mapper = Format::Mapper.new(yml) @modifier = Format::Modifier.new(yml, modifiers) end 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 private attr_reader :modifier, :mapper def nullify_empty_value(value) value.blank? || value.try(:zero?) ? nil : value end end end
Version data entries
5 entries across 5 versions & 1 rubygems