Class: Abstractifier

Inherits:
Object
  • Object
show all
Defined in:
lib/abstractifier.rb

Constant Summary collapse

DEFAULT_MINIMUM_LENGTH =
80
DEFAULT_MAXIMUM_LENGTH =
250

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Abstractifier

Returns a new instance of Abstractifier.



9
10
11
12
13
# File 'lib/abstractifier.rb', line 9

def initialize(options = {})
  @min_length = options.fetch(:min, DEFAULT_MINIMUM_LENGTH)
  @max_length = options.fetch(:max, DEFAULT_MAXIMUM_LENGTH)
  @elider = options.fetch(:elider, '')
end

Instance Attribute Details

#eliderObject

Returns the value of attribute elider.



7
8
9
# File 'lib/abstractifier.rb', line 7

def elider
  @elider
end

#max_lengthObject

Returns the value of attribute max_length.



7
8
9
# File 'lib/abstractifier.rb', line 7

def max_length
  @max_length
end

#min_lengthObject

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