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.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
-
#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 15 16 17 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 8 def initialize word formatted_word = word.strip.gsub(' ', '-') rescue '' param_word = formatted_word.gsub('-', '+') main_url = "http://www.oxfordlearnersdictionaries.com/definition/english/#{formatted_word}?q=#{param_word}" @urls = [ main_url, main_url.gsub('?q=', '1?q=') ] @word = formatted_word @definition = Array.new self 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 |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def examples @examples 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 |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
6 7 8 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 6 def urls @urls 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/oxford_learners_dictionaries/english.rb', line 19 def look_up @urls.each do |url| begin @page = Nokogiri::HTML(open(url)) break rescue OpenURI::HTTPError @page = nil end end return nil if @page.nil? parse self end |