Class: Document
- Inherits:
-
Object
- Object
- Document
- Defined in:
- lib/document.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#content ⇒ Object
Returns the value of attribute content.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #average_word_length ⇒ Object
-
#initialize(title, author, content) ⇒ Document
constructor
A new instance of Document.
- #number_word_characters ⇒ Object
- #word_count ⇒ Object
- #words ⇒ Object
Constructor Details
#initialize(title, author, content) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 |
# File 'lib/document.rb', line 7 def initialize( title, , content ) @title = title @author = @content = content end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
5 6 7 |
# File 'lib/document.rb', line 5 def @author end |
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/document.rb', line 5 def content @content end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/document.rb', line 5 def title @title end |
Instance Method Details
#average_word_length ⇒ Object
21 22 23 |
# File 'lib/document.rb', line 21 def average_word_length number_word_characters / word_count end |
#number_word_characters ⇒ Object
25 26 27 |
# File 'lib/document.rb', line 25 def number_word_characters words.inject( 0 ) { |total, word| total += word.size } end |
#word_count ⇒ Object
17 18 19 |
# File 'lib/document.rb', line 17 def word_count words.size end |
#words ⇒ Object
13 14 15 |
# File 'lib/document.rb', line 13 def words @content.split end |