Class: OpenDictionary::Client
- Inherits:
-
Object
- Object
- OpenDictionary::Client
- Defined in:
- lib/open_dictionary.rb
Constant Summary collapse
- BASE_URL =
'https://raw.githubusercontent.com/vighnesh153/open-dictionary/main/data'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.lookup(word) ⇒ Object
15 16 17 |
# File 'lib/open_dictionary.rb', line 15 def self.lookup(word) new.lookup(word) end |
.lookup!(word) ⇒ Object
19 20 21 |
# File 'lib/open_dictionary.rb', line 19 def self.lookup!(word) new.lookup!(word) end |
Instance Method Details
#lookup(word) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/open_dictionary.rb', line 23 def lookup(word) response = fetch_definition(word) parse_response(response, word) rescue HTTParty::Error => e raise Error, "HTTP Error: #{e.}" rescue JSON::ParserError => e raise Error, "JSON parsing error: #{e.}" end |
#lookup!(word) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/open_dictionary.rb', line 32 def lookup!(word) response = fetch_definition(word, true) parse_response(response, word) rescue HTTParty::Error => e raise Error, "HTTP Error: #{e.}" rescue JSON::ParserError => e raise Error, "JSON parsing error: #{e.}" end |