Class: StyleScanner::Sentence

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/style_scanner/sentence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Sentence

Returns a new instance of Sentence.



9
10
11
12
# File 'lib/style_scanner/sentence.rb', line 9

def initialize(text)
  @text = text
  @problems = []
end

Instance Attribute Details

#problemsObject (readonly)

Returns the value of attribute problems.



7
8
9
# File 'lib/style_scanner/sentence.rb', line 7

def problems
  @problems
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/style_scanner/sentence.rb', line 7

def text
  @text
end

Instance Method Details

#add_problem(problem) ⇒ Object



38
39
40
# File 'lib/style_scanner/sentence.rb', line 38

def add_problem(problem)
  problems << problem
end

#adverbsObject



22
23
24
# File 'lib/style_scanner/sentence.rb', line 22

def adverbs
  part_of_speech("RB")
end

#contains?(word, option_modifications = {}) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/style_scanner/sentence.rb', line 26

def contains?(word, option_modifications = {})
  options = {:strip_case => true}.merge(option_modifications)
  text_to_scan = text
  text_to_scan = stemmed_verbs if options[:stem_verbs]
  text_to_scan = text_to_scan.downcase if options[:strip_case]
  text_to_scan.match(/\b#{word}\b/) 
end

#find_problems_by_type(problem_type) ⇒ Object



14
15
16
# File 'lib/style_scanner/sentence.rb', line 14

def find_problems_by_type(problem_type)
  @problems.select {|problem| problem.class == problem_type}
end

#tagged_wordsObject



18
19
20
# File 'lib/style_scanner/sentence.rb', line 18

def tagged_words
  tagger.tagged_words
end

#to_sObject



46
47
48
# File 'lib/style_scanner/sentence.rb', line 46

def to_s
  "Sentence Obj: text: #{text} problems: #{problems}"
end

#user_friendly_readoutObject



34
35
36
# File 'lib/style_scanner/sentence.rb', line 34

def user_friendly_readout
   problems.flatten.map(&:user_friendly_readout) if with_problems?
end

#with_problems?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/style_scanner/sentence.rb', line 42

def with_problems?
  problems.any?
end