Class: Bable::StatisticString

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/bable/statistic_string.rb

Constant Summary collapse

WORD_REGEX =
/\w+/
SENTENCE_REGEX =
/[^\s.?!:][^.?!:]*[.?!:]+/

Instance Method Summary collapse

Instance Method Details

#average_sentence_lengthObject



30
31
32
# File 'lib/bable/statistic_string.rb', line 30

def average_sentence_length
  characters_count / sentences_count.to_f
end

#average_word_lengthObject



26
27
28
# File 'lib/bable/statistic_string.rb', line 26

def average_word_length
  characters_count / words_count.to_f
end

#characters_countObject



14
15
16
# File 'lib/bable/statistic_string.rb', line 14

def characters_count
  words.join.size
end

#sentencesObject



10
11
12
# File 'lib/bable/statistic_string.rb', line 10

def sentences
  scan(SENTENCE_REGEX)
end

#sentences_countObject



22
23
24
# File 'lib/bable/statistic_string.rb', line 22

def sentences_count
  sentences.size
end

#wordsObject



6
7
8
# File 'lib/bable/statistic_string.rb', line 6

def words
  scan(WORD_REGEX)
end

#words_countObject



18
19
20
# File 'lib/bable/statistic_string.rb', line 18

def words_count
  words.size
end