Class: Genderize::Io::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/genderize/io/base.rb

Direct Known Subclasses

Genderize::Io::Batch::Lookup, Lookup

Constant Summary collapse

DEFAULT_HOST =
'https://api.genderize.io'
HEADER_KEYS =
%w[
  x_rate_limit_limit x_rate_limit_remaining x_rate_reset
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, host: DEFAULT_HOST, country_id: nil, language_id: nil) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
22
23
# File 'lib/genderize/io/base.rb', line 17

def initialize(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
  @name = name
  @host = host
  @country_id = country_id
  @language_id = language_id
  @request = nil
end

Instance Attribute Details

#country_idObject (readonly)

Returns the value of attribute country_id.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def country_id
  @country_id
end

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def data
  @data
end

#hostObject (readonly)

Returns the value of attribute host.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def host
  @host
end

#language_idObject (readonly)

Returns the value of attribute language_id.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def language_id
  @language_id
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def name
  @name
end

#requestObject (readonly)

Returns the value of attribute request.



15
16
17
# File 'lib/genderize/io/base.rb', line 15

def request
  @request
end

Class Method Details

.determine(name, host: DEFAULT_HOST, country_id: nil, language_id: nil) ⇒ Object



25
26
27
28
29
# File 'lib/genderize/io/base.rb', line 25

def self.determine(name, host: DEFAULT_HOST, country_id: nil, language_id: nil)
  klass = new(name, host: host, country_id: country_id, language_id: language_id)
  klass.determine
  klass
end

Instance Method Details

#urlObject



31
32
33
34
# File 'lib/genderize/io/base.rb', line 31

def url
  connector = @host.include?('?') ? '&' : '?'
  "#{@host}#{connector}#{param_name}#{param_country_id}#{param_language_id}"
end