Sha256: 0a43f6f3ca8b662397fe21978db81ad16c6c492cd83936697d9236c483edb1e5

Contents?: true

Size: 617 Bytes

Versions: 5

Compression:

Stored size: 617 Bytes

Contents

module Moip2
  module Util
    class FiltersEncoder
      def self.encode(filters)
        return nil unless filters.is_a? Hash

        encoded_filters = filters.map do |field, value|
          rules = extract_rules(field, value)
          rules.join("|")
        end

        encoded_filters.join("|")
      end

      private

      def self.extract_rules(field, rules)
        rules.map do |type, value|
          return unless %i[gt ge lt le bt in].include?(type)

          content = value.is_a?(Array) ? value.join(",") : value

          "#{field}::#{type}(#{content})"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
moip2-1.3.1 lib/moip2/util/filters_encoder.rb
moip2-1.2.1 lib/moip2/util/filters_encoder.rb
moip2-1.2.0 lib/moip2/util/filters_encoder.rb
moip2-1.1.0 lib/moip2/util/filters_encoder.rb
moip2-1.0.0 lib/moip2/util/filters_encoder.rb