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

Version Path
xml_data_extractor-0.5.0 lib/src/format/formatter.rb
xml_data_extractor-0.4.0 lib/src/format/formatter.rb
xml_data_extractor-0.3.0 lib/src/format/formatter.rb
xml_data_extractor-0.2.0 lib/src/format/formatter.rb
xml_data_extractor-0.1.0 lib/src/format/formatter.rb