Sha256: 9ef71b9fa52522a3557c9a26e534eb3ca48a27e83be996fb31e4eb1b9ea669e3

Contents?: true

Size: 562 Bytes

Versions: 6

Compression:

Stored size: 562 Bytes

Contents

module DeepL
  class Configuration
    ATTRIBUTES = %i[auth_key host].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'
    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

6 entries across 6 versions & 1 rubygems

Version Path
deepl-rb-2.1.0 lib/deepl/configuration.rb
deepl-rb-2.0.0 lib/deepl/configuration.rb
deepl-rb-1.0.1 lib/deepl/configuration.rb
deepl-rb-1.0.0 lib/deepl/configuration.rb
deepl-rb-0.0.1 lib/deepl/configuration.rb
deepl-rb-0.0.0 lib/deepl/configuration.rb