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
30 31 32 |
# File 'lib/bable/statistic_string.rb', line 30 def average_sentence_length characters_count / sentences_count.to_f end |
#average_word_length ⇒ Object
26 27 28 |
# File 'lib/bable/statistic_string.rb', line 26 def average_word_length characters_count / words_count.to_f end |
#characters_count ⇒ Object
14 15 16 |
# File 'lib/bable/statistic_string.rb', line 14 def characters_count words.join.size end |
#sentences ⇒ Object
10 11 12 |
# File 'lib/bable/statistic_string.rb', line 10 def sentences scan(SENTENCE_REGEX) end |
#sentences_count ⇒ Object
22 23 24 |
# File 'lib/bable/statistic_string.rb', line 22 def sentences_count sentences.size end |
#words ⇒ Object
6 7 8 |
# File 'lib/bable/statistic_string.rb', line 6 def words scan(WORD_REGEX) end |
#words_count ⇒ Object
18 19 20 |
# File 'lib/bable/statistic_string.rb', line 18 def words_count words.size end |