Sha256: 98691949e8ffc20f4b287ac725fa44865eab89e64eb6d2c6bea99345ec719185

Contents?: true

Size: 594 Bytes

Versions: 3

Compression:

Stored size: 594 Bytes

Contents

module DeepL
  class Configuration
    ATTRIBUTES = %i[auth_key host version].freeze

    attr_accessor(*ATTRIBUTES)

    def initialize(data = {})
      data.each { |key, value| send("#{key}=", value) }
      @auth_key ||= ENV['DEEPL_AUTH_KEY']
      @host ||= 'https://api.deepl.com'
      @version ||= 'v2'
    end

    def validate!
      raise Exceptions::Error, 'auth_key not provided' if auth_key.nil? || auth_key.empty?
    end

    def attributes
      ATTRIBUTES.map { |attr| [attr, send(attr)] }.to_h
    end

    def ==(other)
      attributes == other.attributes
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deepl-rb-2.2.2 lib/deepl/configuration.rb
deepl-rb-2.2.1 lib/deepl/configuration.rb
deepl-rb-2.2.0 lib/deepl/configuration.rb