Class: Gendered::Guesser
- Inherits:
-
Object
- Object
- Gendered::Guesser
- Defined in:
- lib/gendered/guesser.rb
Constant Summary collapse
- ENDPOINT =
"https://api.genderize.io".freeze
- USAGE_HEADERS =
{ "X-Rate-Limit-Limit" => :limit, "X-Rate-Limit-Remaining" => :remaining, "X-Rate-Reset" => :reset }.freeze
Instance Attribute Summary collapse
-
#names ⇒ Object
Returns the value of attribute names.
-
#options ⇒ Object
Returns the value of attribute options.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #guess! ⇒ Object
-
#initialize(names, options = {}) ⇒ Guesser
constructor
A new instance of Guesser.
Constructor Details
#initialize(names, options = {}) ⇒ Guesser
Returns a new instance of Guesser.
15 16 17 18 19 20 21 22 |
# File 'lib/gendered/guesser.rb', line 15 def initialize(names, = {}) @names = Array(names) raise ArgumentError, "names cannot be empty" if @names.empty? @options = Gendered.config.merge( || {}) @options[:connection] ||= {} @usage = { :limit => nil, :remaining => nil, :reset => nil } end |
Instance Attribute Details
#names ⇒ Object
Returns the value of attribute names.
13 14 15 |
# File 'lib/gendered/guesser.rb', line 13 def names @names end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/gendered/guesser.rb', line 13 def @options end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
12 13 14 |
# File 'lib/gendered/guesser.rb', line 12 def usage @usage end |
Instance Method Details
#guess! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gendered/guesser.rb', line 24 def guess! response = request() update_usage(response) body = parse(response.body) case response.code when 200 create_names(body) when 429 raise RateLimitError.new(body["error"], *@usage.values_at(:limit, :remaining, :reset)) else raise GenderedError.new(body["error"]) end end |