Class: Sentencemate::Paragraph

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

Overview

object meant to simulate a paragraph or block of text.

Instance Method Summary collapse

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

#lettercountObject



101
102
103
# File 'lib/Sentencemate.rb', line 101

def lettercount
  return @paragraph.split("").length
end

#paragraphObject



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

#wordcountObject



104
105
106
# File 'lib/Sentencemate.rb', line 104

def wordcount
  return @paragraph.split(" ").length
end