Class: Document

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, author, content )
  @title = title
  @author = author
  @content = content
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



5
6
7
# File 'lib/document.rb', line 5

def author
  @author
end

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/document.rb', line 5

def content
  @content
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/document.rb', line 5

def title
  @title
end

Instance Method Details

#average_word_lengthObject



21
22
23
# File 'lib/document.rb', line 21

def average_word_length
  number_word_characters / word_count
end

#number_word_charactersObject



25
26
27
# File 'lib/document.rb', line 25

def number_word_characters
  words.inject( 0 ) { |total, word| total += word.size }
end

#word_countObject



17
18
19
# File 'lib/document.rb', line 17

def word_count
  words.size
end

#wordsObject



13
14
15
# File 'lib/document.rb', line 13

def words
  @content.split
end