Sha256: fdb56bd3a1d21081269e502c2b6e7e140fe6fd3ab3a522e9b476c020dbe62e41

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

module Mercy
  class Report
    class Range < Report::ActiveRecord
      ALLOWED_PARAMETERS=[:period, :maximum, :minimum]
      DEFAULT_OPTION = {
        period: 1.day,
        scope: :all,
      }

      expose :scope
      expose :maximum, type: :infinity_float, default: 'inf'
      expose :minimum, type: :infinity_float, default: '-inf'

      def initialize(options)
        super(DEFAULT_OPTION.merge(options))
      end

      def scoped
        @scoped ||= fetch_scoped(last_entries, scope)
      end

      def error?
        @error ||= !count_in_range?
      end

      def as_json
        {
          status: status,
          count: count
        }
      end

      def count
        scoped.count
      end

      private

      def range
        (minimum..maximum)
      end

      def count_in_range?
        return range.include?(count)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercy-1.6.0 lib/mercy/report/range.rb
mercy-1.5.0 lib/mercy/report/range.rb