Sha256: 259bc8cb0eb5e8b866bac892eaf11cdd039c0db7cc327814ff275fa8f088b2f9

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
xml_data_extractor-0.7.0 lib/src/format/formatter.rb
xml_data_extractor-0.6.0 lib/src/format/formatter.rb