Class: Abstractifier
- Inherits:
-
Object
- Object
- Abstractifier
- Defined in:
- lib/abstractifier.rb
Constant Summary collapse
- DEFAULT_MINIMUM_LENGTH =
80
- DEFAULT_MAXIMUM_LENGTH =
250
Instance Attribute Summary collapse
-
#elider ⇒ Object
Returns the value of attribute elider.
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#min_length ⇒ Object
Returns the value of attribute min_length.
Instance Method Summary collapse
- #abstractify(string) ⇒ Object
-
#initialize(options = {}) ⇒ Abstractifier
constructor
A new instance of Abstractifier.
Constructor Details
#initialize(options = {}) ⇒ Abstractifier
Returns a new instance of Abstractifier.
9 10 11 12 13 |
# File 'lib/abstractifier.rb', line 9 def initialize( = {}) @min_length = .fetch(:min, DEFAULT_MINIMUM_LENGTH) @max_length = .fetch(:max, DEFAULT_MAXIMUM_LENGTH) @elider = .fetch(:elider, '…') end |
Instance Attribute Details
#elider ⇒ Object
Returns the value of attribute elider.
7 8 9 |
# File 'lib/abstractifier.rb', line 7 def elider @elider end |
#max_length ⇒ Object
Returns the value of attribute max_length.
7 8 9 |
# File 'lib/abstractifier.rb', line 7 def max_length @max_length end |
#min_length ⇒ Object
Returns the value of attribute min_length.
7 8 9 |
# File 'lib/abstractifier.rb', line 7 def min_length @min_length end |
Instance Method Details
#abstractify(string) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/abstractifier.rb', line 15 def abstractify(string) output = '' extract_sentences(string).each do |sentence| output << "#{sentence}. " break if output.length >= min_length end output = forcibly_truncate(output) if output.length > max_length output = tidy(output) output end |