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.



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

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.



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

def country_id
  @country_id
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#language_idObject (readonly)

Returns the value of attribute language_id.



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

def language_id
  @language_id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

Class Method Details

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



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

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

Instance Method Details

#urlObject



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

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