Class: Wotd::Word
- Inherits:
-
Object
- Object
- Wotd::Word
- Defined in:
- lib/wotd/word.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#example ⇒ Object
Returns the value of attribute example.
-
#fact ⇒ Object
Returns the value of attribute fact.
-
#syllables ⇒ Object
Returns the value of attribute syllables.
-
#wotd ⇒ Object
Returns the value of attribute wotd.
Class Method Summary collapse
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
2 3 4 |
# File 'lib/wotd/word.rb', line 2 def definition @definition end |
#example ⇒ Object
Returns the value of attribute example.
2 3 4 |
# File 'lib/wotd/word.rb', line 2 def example @example end |
#fact ⇒ Object
Returns the value of attribute fact.
2 3 4 |
# File 'lib/wotd/word.rb', line 2 def fact @fact end |
#syllables ⇒ Object
Returns the value of attribute syllables.
2 3 4 |
# File 'lib/wotd/word.rb', line 2 def syllables @syllables end |
#wotd ⇒ Object
Returns the value of attribute wotd.
2 3 4 |
# File 'lib/wotd/word.rb', line 2 def wotd @wotd end |
Class Method Details
.scrape_word ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wotd/word.rb', line 10 def self.scrape_word # go to site, find wotd # extract properties # instantiate word doc = Nokogiri::HTML(open("http://www.merriam-webster.com/word-of-the-day")) word = self.new word.wotd = doc.search("h1").last.text word.syllables = doc.search("div.word-attributes span.word-syllables").text word.definition = doc.search( '//h2[text()="Definition"]/following::p[not(preceding::h2[text()="Examples"])]' ).text word.example = doc.search('//*[preceding-sibling::h2[2]]').first.text word.fact = doc.search("div.wod-did-you-know-container p").text word end |
.today ⇒ Object
4 5 6 7 8 |
# File 'lib/wotd/word.rb', line 4 def self.today word = [] word << self.scrape_word word end |