Sha256: df42e9124b204db795f6e9a0ca89d7f42508cdb4f4ea80f0108f461d9751978e

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

require 'tzinfo'

module BellyWash
  class Configuration
    attr_accessor :driver, :track_ranges, :separator, :time_zone,
                  :beginning_of_week

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

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

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

    def ranges
      return @ranges if blank?(track_ranges)

      @ranges & track_ranges
    end

    private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
belly_wash-0.1.1 lib/belly_wash/configuration.rb