Class: AnkiTranslator::References::MacmillanDictionary
- Inherits:
-
Object
- Object
- AnkiTranslator::References::MacmillanDictionary
- Defined in:
- lib/vocab_to_anki/references/macmillan_dictionary.rb
Constant Summary collapse
- URL =
"https://www.macmillandictionary.com/"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #fetch_definitions(term) ⇒ Object
-
#initialize ⇒ MacmillanDictionary
constructor
A new instance of MacmillanDictionary.
Constructor Details
#initialize ⇒ MacmillanDictionary
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.("I Accept") end |
Instance Attribute Details
#name ⇒ Object (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 |
#session ⇒ Object (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 |