Class: DeepL::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/deepl/configuration.rb

Constant Summary collapse

ATTRIBUTES =
%i[auth_key host].freeze

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
# File 'lib/deepl/configuration.rb', line 7

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

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/deepl/configuration.rb', line 21

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

#attributesObject



17
18
19
# File 'lib/deepl/configuration.rb', line 17

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

#validate!Object

Raises:



13
14
15
# File 'lib/deepl/configuration.rb', line 13

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