Sha256: c80010c13fad08227981edf1ae245257d90352b4578660e954c27dfa5011ca83

Contents?: true

Size: 800 Bytes

Versions: 31

Compression:

Stored size: 800 Bytes

Contents

module Workarea
  class HashUpdate
    def self.parse_values(value)
      parsed = CSV.parse(value).first
      parsed.map(&:to_s).map(&:strip).reject(&:blank?) if parsed.present?
    end

    def initialize(adds: [], updates: [], removes: [])
      @adds = Array(adds).flatten.each_slice(2).to_a
      @updates = Array(updates).flatten.each_slice(2).to_a
      @removes = Array(removes).flatten
    end

    def apply(hash)
      @adds.each do |tuple|
        key, value = *tuple
        hash[key] = self.class.parse_values(value)
      end

      @updates.each do |tuple|
        key, value = *tuple
        hash[key] = self.class.parse_values(value)
      end

      @removes.each do |key|
        hash.delete(key)
      end

      hash.delete_if { |k, v| k.blank? || v.blank? }
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
workarea-core-3.5.9 app/services/workarea/hash_update.rb
workarea-core-3.4.31 app/services/workarea/hash_update.rb
workarea-core-3.5.8 app/services/workarea/hash_update.rb
workarea-core-3.4.30 app/services/workarea/hash_update.rb
workarea-core-3.5.7 app/services/workarea/hash_update.rb
workarea-core-3.4.29 app/services/workarea/hash_update.rb
workarea-core-3.5.6 app/services/workarea/hash_update.rb
workarea-core-3.4.28 app/services/workarea/hash_update.rb
workarea-core-3.5.5 app/services/workarea/hash_update.rb
workarea-core-3.4.27 app/services/workarea/hash_update.rb
workarea-core-3.5.4 app/services/workarea/hash_update.rb
workarea-core-3.4.26 app/services/workarea/hash_update.rb
workarea-core-3.5.3 app/services/workarea/hash_update.rb
workarea-core-3.4.25 app/services/workarea/hash_update.rb
workarea-core-3.5.2 app/services/workarea/hash_update.rb
workarea-core-3.4.24 app/services/workarea/hash_update.rb
workarea-core-3.5.1 app/services/workarea/hash_update.rb
workarea-core-3.4.23 app/services/workarea/hash_update.rb
workarea-core-3.4.22 app/services/workarea/hash_update.rb
workarea-core-3.5.0 app/services/workarea/hash_update.rb