Class: Dictionary::Word
- Inherits:
-
Object
- Object
- Dictionary::Word
- Defined in:
- lib/dictionary/word.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#part_of_speech ⇒ Object
Returns the value of attribute part_of_speech.
-
#pronounciation ⇒ Object
Returns the value of attribute pronounciation.
-
#word_name ⇒ Object
Returns the value of attribute word_name.
-
#word_type ⇒ Object
Returns the value of attribute word_type.
Class Method Summary collapse
- .all ⇒ Object
- .find_a_word(search) ⇒ Object
- .new_word_from_search(hash) ⇒ Object
- .new_word_of_the_day(hash) ⇒ Object
- .searched_words ⇒ Object
- .todays_word ⇒ Object
- .words_of_the_day ⇒ Object
Instance Method Summary collapse
-
#initialize(word_name = nil, date = nil, part_of_speech = nil, definition = nil, pronounciation = nil, word_type = nil) ⇒ Word
constructor
A new instance of Word.
Constructor Details
#initialize(word_name = nil, date = nil, part_of_speech = nil, definition = nil, pronounciation = nil, word_type = nil) ⇒ Word
Returns a new instance of Word.
7 8 9 10 11 12 13 14 |
# File 'lib/dictionary/word.rb', line 7 def initialize(word_name = nil, date = nil, part_of_speech = nil, definition= nil, pronounciation = nil, word_type = nil) @word_name = word_name @date = date @part_of_speech = part_of_speech @pronounciation = pronounciation @definition = definition @word_type = word_type end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def date @date end |
#definition ⇒ Object
Returns the value of attribute definition.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def definition @definition end |
#part_of_speech ⇒ Object
Returns the value of attribute part_of_speech.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def part_of_speech @part_of_speech end |
#pronounciation ⇒ Object
Returns the value of attribute pronounciation.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def pronounciation @pronounciation end |
#word_name ⇒ Object
Returns the value of attribute word_name.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def word_name @word_name end |
#word_type ⇒ Object
Returns the value of attribute word_type.
3 4 5 |
# File 'lib/dictionary/word.rb', line 3 def word_type @word_type end |
Class Method Details
.all ⇒ Object
40 41 42 |
# File 'lib/dictionary/word.rb', line 40 def self.all @@all end |
.find_a_word(search) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/dictionary/word.rb', line 68 def self.find_a_word(search) @@all.detect do |w| if w.word_name == search w else nil end end end |
.new_word_from_search(hash) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dictionary/word.rb', line 28 def self.new_word_from_search(hash) word = self.new word.word_name = hash[:word_name] word.date = hash[:date] word.part_of_speech = hash[:part_of_speech] word.definition = hash[:definition] word.pronounciation = hash[:pronounciation] word.word_type = hash[:word_type] @@all << word word end |
.new_word_of_the_day(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dictionary/word.rb', line 16 def self.new_word_of_the_day(hash) word = self.new word.word_name = hash[:word_name] word.date = hash[:date] word.part_of_speech = hash[:part_of_speech] word.definition = hash[:definition] word.pronounciation = hash[:pronounciation] word.word_type = hash[:word_type] @@all << word word end |
.searched_words ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/dictionary/word.rb', line 54 def self.searched_words searched_words = [] @@all.each do |w| if w.word_type == "search" searched_words << w end end searched_words end |
.todays_word ⇒ Object
64 65 66 |
# File 'lib/dictionary/word.rb', line 64 def self.todays_word @@all.detect {|w| w.date == Date.today} end |
.words_of_the_day ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/dictionary/word.rb', line 44 def self.words_of_the_day words = [] @@all.each do |w| if w.word_type == "daily" words << w end end words end |