Class: AnkiTranslator::References::MerriamWebster

Inherits:
Object
  • Object
show all
Defined in:
lib/vocab_to_anki/references/merriam_webster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMerriamWebster

Returns a new instance of MerriamWebster.



8
9
10
11
12
13
14
15
16
# File 'lib/vocab_to_anki/references/merriam_webster.rb', line 8

def initialize
  @name = :merriam_webster
  params = { key: AnkiTranslator.configuration.merriam_webster_api_key }
  headers = { "Content-Type" => "application/json" }
  @conn = Faraday.new(url: AnkiTranslator.configuration.merriam_webster_api_url, params: params,
                      headers: headers) do |f|
    f.response :json
  end
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



6
7
8
# File 'lib/vocab_to_anki/references/merriam_webster.rb', line 6

def conn
  @conn
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/vocab_to_anki/references/merriam_webster.rb', line 6

def name
  @name
end

#sessionObject (readonly)

Returns the value of attribute session.



6
7
8
# File 'lib/vocab_to_anki/references/merriam_webster.rb', line 6

def session
  @session
end

Instance Method Details

#fetch_definitions(term) ⇒ Object



18
19
20
21
22
23
# File 'lib/vocab_to_anki/references/merriam_webster.rb', line 18

def fetch_definitions(term)
  definitions = search(term)
  definitions.map do |d|
    Definition.new(text: d, source: name)
  end
end