Sha256: 40e375cb3634903c5bc2f875f2b5bdc4c925986b37b278d05383b5d7089ae36a

Contents?: true

Size: 752 Bytes

Versions: 62

Compression:

Stored size: 752 Bytes

Contents

module Workarea
  class CleanRangeFacets
    def initialize(raw)
      @raw = raw.to_h
    end

    def result
      cleaned_ranges = @raw.inject({}) do |result, (name, ranges)|
        result[name] = clean_ranges(ranges)
        result
      end

      cleaned_ranges.reject { |n, f| n.blank? || f.blank? }
    end

    private

    def clean_ranges(ranges)
      ranges
        .map do |range|
          if range['to'].present?
            range['to'] = range['to'].to_f
          else
            range.delete('to')
          end

          if range['from'].present?
            range['from'] = range['from'].to_f
          else
            range.delete('from')
          end

          range
        end
        .reject(&:blank?)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.26 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.45 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.25 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.23 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.44 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.22 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.43 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.21 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.42 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.20 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.41 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.19 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.40 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.18 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.39 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.17 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.38 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.16 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.37 app/services/workarea/clean_range_facets.rb