Module: Piola::Importance

Defined in:
lib/piola/importance.rb

Instance Method Summary collapse

Instance Method Details

#count_wordsObject

Counts words in a string



6
7
8
9
10
11
12
# File 'lib/piola/importance.rb', line 6

def count_words
  str = self
  str = str.gsub(/( )+/, ' ')
  str = str.strip
  str = str.split(" ")
  str.length
end

#important_wordsObject

Important words from a string



31
32
33
34
35
36
# File 'lib/piola/importance.rb', line 31

def important_words
  str = self
  str = str.gsub(/ +/, ' ').strip
  parts = str.split(' ')
  parts.reject { |p| p.length <= 3 }.join(' ')
end

#just_words(options = {}) ⇒ Object

Return just the most important clean words of a string



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/piola/importance.rb', line 39

def just_words(options = {})
  str = self
  str = str.
          clean_text.
          remove_quotes.
          strip_tags.
          remove_all_parenthesis.
          downcase

  str = str.important_words       unless options[:small_words]
  str = str.remove_special_chars  unless options[:leave_special]
  str = str.only_letters
  str
end

#longest_parragraphObject

Get most important parragraph from a text



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/piola/importance.rb', line 15

def longest_parragraph
  parragraphs = self.split("\n")
  longest_p = ''

  parragraphs.each do |p|
    p = p.strip

    if p.length >= longest_p.length
      longest_p = p
    end
  end

  longest_p
end