Sha256: 7388cb39c604032fe3c75d6b16bd2a8a9d4bdf8b0b6d3c32cfc38263fb0d2cea

Contents?: true

Size: 926 Bytes

Versions: 5

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

require 'tzinfo'

module Trifle
  module Stats
    class Configuration
      attr_writer :driver
      attr_accessor :track_ranges, :time_zone, :beginning_of_week, :designator

      def initialize
        @ranges = %i[minute hour day week month quarter year]
        @beginning_of_week = :monday
        @time_zone = 'GMT'
        @designator = nil
      end

      def tz
        TZInfo::Timezone.get(@time_zone)
      rescue TZInfo::InvalidTimezoneIdentifier => e
        puts "Trifle: #{e} - #{time_zone}; Defaulting to GMT."

        TZInfo::Timezone.get('GMT')
      end

      def ranges
        return @ranges if blank?(track_ranges)

        @ranges & track_ranges
      end

      def driver
        raise DriverNotFound if @driver.nil?

        @driver
      end

      private

      def blank?(obj)
        obj.respond_to?(:empty?) ? !!obj.empty? : !obj
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trifle-stats-1.3.1 lib/trifle/stats/configuration.rb
trifle-stats-1.3.0 lib/trifle/stats/configuration.rb
trifle-stats-1.2.0 lib/trifle/stats/configuration.rb
trifle-stats-1.1.2 lib/trifle/stats/configuration.rb
trifle-stats-1.1.1 lib/trifle/stats/configuration.rb