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



32
33
34
# File 'lib/bable/statistic_string.rb', line 32

def average_sentence_length
  characters_count / sentences_count.to_f
end

#average_word_lengthObject



28
29
30
# File 'lib/bable/statistic_string.rb', line 28

def average_word_length
  characters_count / words_count.to_f
end

#characters_countObject



16
17
18
# File 'lib/bable/statistic_string.rb', line 16

def characters_count
  words.join.size
end

#sentencesObject



12
13
14
# File 'lib/bable/statistic_string.rb', line 12

def sentences
  scan(SENTENCE_REGEX)
end

#sentences_countObject



24
25
26
# File 'lib/bable/statistic_string.rb', line 24

def sentences_count
  sentences.size
end

#wordsObject



8
9
10
# File 'lib/bable/statistic_string.rb', line 8

def words
  scan(WORD_REGEX)
end

#words_countObject



20
21
22
# File 'lib/bable/statistic_string.rb', line 20

def words_count
  words.size
end