Class: OpenDictionary::Client

Inherits:
Object
  • Object
show all
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

Instance Method Details

#lookup(word) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/open_dictionary.rb', line 19

def lookup(word)
  response = fetch_definition(word)
  parse_response(response, word)
rescue HTTParty::Error => e
  raise Error, "HTTP Error: #{e.message}"
rescue JSON::ParserError => e
  raise Error, "JSON parsing error: #{e.message}"
end