Class: OxfordLearnersDictionaries::English
- Inherits:
-
Object
- Object
- OxfordLearnersDictionaries::English
- Defined in:
- lib/oxford_learners_dictionaries/english.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
-
#initialize(word) ⇒ English
constructor
A new instance of English.
- #look_up ⇒ Object
Constructor Details
#initialize(word) ⇒ English
Returns a new instance of English.
8 9 10 11 12 13 14 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 8 def initialize word formatted_word = word.strip.gsub(' ', '-') rescue '' param_word = formatted_word.gsub('-', '+') @url = "http://www.oxfordlearnersdictionaries.com/definition/english/#{formatted_word}?q=#{param_word}" @word = formatted_word @definition = Hash.new end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def definition @definition end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def url @url end |
#word ⇒ Object (readonly)
Returns the value of attribute word.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def word @word end |
Instance Method Details
#look_up ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 16 def look_up begin @page = Nokogiri::HTML(open(@url)) @page.css('.idm-gs').remove parse rescue OpenURI::HTTPError nil end self.definition end |