Class: Bable::StatisticString
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Bable::StatisticString
- Defined in:
- lib/bable/statistic_string.rb
Constant Summary collapse
- WORD_REGEX =
/\w+/
- SENTENCE_REGEX =
/[^\s.?!:][^.?!:]*[.?!:]+/
Instance Method Summary collapse
- #average_sentence_length ⇒ Object
- #average_word_length ⇒ Object
- #characters_count ⇒ Object
- #sentences ⇒ Object
- #sentences_count ⇒ Object
- #words ⇒ Object
- #words_count ⇒ Object
Instance Method Details
#average_sentence_length ⇒ Object
32 33 34 |
# File 'lib/bable/statistic_string.rb', line 32 def average_sentence_length characters_count / sentences_count.to_f end |
#average_word_length ⇒ Object
28 29 30 |
# File 'lib/bable/statistic_string.rb', line 28 def average_word_length characters_count / words_count.to_f end |
#characters_count ⇒ Object
16 17 18 |
# File 'lib/bable/statistic_string.rb', line 16 def characters_count words.join.size end |
#sentences ⇒ Object
12 13 14 |
# File 'lib/bable/statistic_string.rb', line 12 def sentences scan(SENTENCE_REGEX) end |
#sentences_count ⇒ Object
24 25 26 |
# File 'lib/bable/statistic_string.rb', line 24 def sentences_count sentences.size end |
#words ⇒ Object
8 9 10 |
# File 'lib/bable/statistic_string.rb', line 8 def words scan(WORD_REGEX) end |
#words_count ⇒ Object
20 21 22 |
# File 'lib/bable/statistic_string.rb', line 20 def words_count words.size end |