Class: Sentencemate::Paragraph
- Inherits:
-
Object
- Object
- Sentencemate::Paragraph
- Defined in:
- lib/Sentencemate.rb
Overview
object meant to simulate a paragraph or block of text.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #checkforword(str) ⇒ Object
- #cutstring(str, start, stop) ⇒ Object
-
#initialize(text) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #lettercount ⇒ Object
- #paragraph ⇒ Object
- #word_at_index(i) ⇒ Object
- #wordcount ⇒ Object
Constructor Details
#initialize(text) ⇒ Paragraph
Returns a new instance of Paragraph.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/Sentencemate.rb', line 69 def initialize(text) @paragraph = text @sentence_box = [] count = 0 until text.length == 0 do if text[count] == "." @sentence_box << Sentence.new(text[0..count]) text = self.cutstring(text, 0, count) count = 0 elsif text[count] == "?" @sentence_box << Sentence.new(text[0..count]) text = self.cutstring(text, 0, count) count = 0 elsif text[count] == "!" @sentence_box << Sentence.new(text[0..count]) text = self.cutstring(text, 0, count) count = 0 else count += 1 end end end |
Instance Method Details
#[](i) ⇒ Object
95 96 97 |
# File 'lib/Sentencemate.rb', line 95 def [](i) @sentence_box[i] end |
#checkforword(str) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/Sentencemate.rb', line 107 def checkforword(str) for sentence in @sentence_box if sentence.checkforword(str) return true end end return false end |
#cutstring(str, start, stop) ⇒ Object
91 92 93 94 |
# File 'lib/Sentencemate.rb', line 91 def cutstring(str, start, stop) str[start..stop] = "" return str end |
#lettercount ⇒ Object
101 102 103 |
# File 'lib/Sentencemate.rb', line 101 def lettercount return @paragraph.split("").length end |
#paragraph ⇒ Object
98 99 100 |
# File 'lib/Sentencemate.rb', line 98 def paragraph return @paragraph end |
#word_at_index(i) ⇒ Object
115 116 117 |
# File 'lib/Sentencemate.rb', line 115 def word_at_index(i) return @paragraph.split(" ")[i] end |
#wordcount ⇒ Object
104 105 106 |
# File 'lib/Sentencemate.rb', line 104 def wordcount return @paragraph.split(" ").length end |