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



16
17
18
# File 'lib/open_dictionary.rb', line 16

def self.lookup(word)
  new.lookup(word)
end

.lookup!(word) ⇒ Object



20
21
22
# File 'lib/open_dictionary.rb', line 20

def self.lookup!(word)
  new.lookup!(word)
end

Instance Method Details

#lookup(word) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/open_dictionary.rb', line 24

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

#lookup!(word) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/open_dictionary.rb', line 33

def lookup!(word)
  response = fetch_definition(word, true)
  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