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.15 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.36 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.14 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.35 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.13 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.34 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.12 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.33 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.11 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.10 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.32 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.9 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.31 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.8 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.30 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.7 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.29 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.6 app/services/workarea/clean_range_facets.rb
workarea-core-3.4.28 app/services/workarea/clean_range_facets.rb
workarea-core-3.5.5 app/services/workarea/clean_range_facets.rb