Sha256: 276895f17ef55be4dd4edbfef37187e86da9f3d2f17db765a0df3741bc4a2cbb

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

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

        json_parse :scope
        json_parse :minimum, :maximum, type: :integer

        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) unless (maximum.nil? || minimum.nil?)
          return count >= minimum unless minimum.nil?
          return count <= maximum unless maximum.nil?
          true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bidu-house-1.1.0 lib/bidu/house/report/range.rb