Sha256: fbf09607215bf8b0493769af97f86111f6dbe4dd9f0710d71a75f4f3ef60d07a

Contents?: true

Size: 887 Bytes

Versions: 6

Compression:

Stored size: 887 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

      def initialize
        @ranges = %i[minute hour day week month quarter year]
        @beginning_of_week = :monday
        @time_zone = 'GMT'
      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

6 entries across 6 versions & 1 rubygems

Version Path
trifle-stats-1.0.0 lib/trifle/stats/configuration.rb
trifle-stats-0.4.1 lib/trifle/stats/configuration.rb
trifle-stats-0.4.0 lib/trifle/stats/configuration.rb
trifle-stats-0.3.2 lib/trifle/stats/configuration.rb
trifle-stats-0.3.1 lib/trifle/stats/configuration.rb
trifle-stats-0.3.0 lib/trifle/stats/configuration.rb