Class: DeepL::Configuration

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

Constant Summary collapse

ATTRIBUTES =
i[auth_key host version].freeze

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
# File 'lib/deepl/configuration.rb', line 9

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

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/deepl/configuration.rb', line 24

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

#attributesObject



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

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

#validate!Object

Raises:



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

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