Class: AnkiTranslator::References::MacmillanDictionary

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

Constant Summary collapse

URL =
"https://www.macmillandictionary.com/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMacmillanDictionary

Returns a new instance of MacmillanDictionary.



10
11
12
13
14
15
# File 'lib/vocab_to_anki/references/macmillan_dictionary.rb', line 10

def initialize
  @name = :macmillan
  @session = Capybara::Session.new(AnkiTranslator.configuration.selenium_driver)
  @session.visit(URL)
  @session.click_button("I Accept")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vocab_to_anki/references/macmillan_dictionary.rb', line 8

def name
  @name
end

#sessionObject (readonly)

Returns the value of attribute session.



8
9
10
# File 'lib/vocab_to_anki/references/macmillan_dictionary.rb', line 8

def session
  @session
end

Instance Method Details

#fetch_definitions(term) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/vocab_to_anki/references/macmillan_dictionary.rb', line 17

def fetch_definitions(term)
  search(term)
  definitions = session.all("span", class: "DEFINITION")
  return nil unless definitions&.any?

  definitions.map do |d|
    examples = find_examples(d)
    Definition.new(text: d.text, examples: examples, source: name)
  end
end