class Gutenug::Paragraph
Public Class Methods
new(blob)
click to toggle source
# File lib/gutenug/paragraph.rb, line 3 def initialize(blob) segmenter = PragmaticSegmenter::Segmenter.new(text: blob.join(' ')) @sentences = segmenter.segment _validate end
Public Instance Methods
invalid!()
click to toggle source
# File lib/gutenug/paragraph.rb, line 21 def invalid! @invalid = true end
invalid?()
click to toggle source
# File lib/gutenug/paragraph.rb, line 25 def invalid? @invalid end
sentences()
click to toggle source
# File lib/gutenug/paragraph.rb, line 13 def sentences @sentences end
status()
click to toggle source
# File lib/gutenug/paragraph.rb, line 33 def status if invalid? :invalid elsif suspect? :suspect else :valid end end
suspect?()
click to toggle source
# File lib/gutenug/paragraph.rb, line 29 def suspect? @suspect end
to_s()
click to toggle source
# File lib/gutenug/paragraph.rb, line 9 def to_s @sentences.join(" ") end
valid!()
click to toggle source
# File lib/gutenug/paragraph.rb, line 17 def valid! @invalid = false end
Private Instance Methods
_validate()
click to toggle source
# File lib/gutenug/paragraph.rb, line 45 def _validate @invalid = @sentences.empty? @invalid ||= @sentences.length == 1 && @sentences.first !~ /[?!.]+["'_)\]]*$/ && sentences.first !~ /[-][-]$/ @suspect = @invalid @suspect ||= @sentences.all? { |sentence| sentence !~ /[a-z]/ } end