Class: Wotd::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/wotd/word.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#definitionObject

Returns the value of attribute definition.



2
3
4
# File 'lib/wotd/word.rb', line 2

def definition
  @definition
end

#exampleObject

Returns the value of attribute example.



2
3
4
# File 'lib/wotd/word.rb', line 2

def example
  @example
end

#factObject

Returns the value of attribute fact.



2
3
4
# File 'lib/wotd/word.rb', line 2

def fact
  @fact
end

#syllablesObject

Returns the value of attribute syllables.



2
3
4
# File 'lib/wotd/word.rb', line 2

def syllables
  @syllables
end

#wotdObject

Returns the value of attribute wotd.



2
3
4
# File 'lib/wotd/word.rb', line 2

def wotd
  @wotd
end

Class Method Details

.scrape_wordObject



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

.todayObject



4
5
6
7
8
# File 'lib/wotd/word.rb', line 4

def self.today
  word = []
  word << self.scrape_word
  word
end