class InevitableCacophony::Parser::SectionedText

Constants

PARAGRAPH_DELIMITER
SENTENCE_DELIMITER

Attributes

sections[RW]

Public Class Methods

new(description, delimiter=PARAGRAPH_DELIMITER) click to toggle source

@param description [String] The description to parse @param delimiter [String,Regex] The delimiter between string sections. Defaults to splitting by paragraphs.

# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 17
def initialize(description, delimiter=PARAGRAPH_DELIMITER)
        @sections = description.split(delimiter).map(&:strip)
end

Public Instance Methods

find(key) click to toggle source

Find a section (paragraph, sentence, etc.) of the description matching a given regular expression. @param key [Regex] @return [String]

# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 27
def find(key)
        find_all(key).first
end
find_all(key) click to toggle source

Find all sections matching a given key @param key [Regex] @return [Array<String>]

# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 34
def find_all(key)
        @sections.select { |s| key.match?(s) } || raise("No match for #{key.inspect} in #{@sections.inspect}")
end
find_all_paragraphs(key) click to toggle source

As above but finds all matching paragraphs. @param key [Regex] @return [Array<SectionedText>]

# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 49
def find_all_paragraphs(key)
        find_all(key).map do |string|
                SectionedText.new(string, SENTENCE_DELIMITER)
        end
end
find_paragraph(key) click to toggle source

Find a paragraph within the description, and break it up into sentences. @param key [Regex] @return [SectionedText] The paragraph, split into sentences.

# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 41
def find_paragraph(key)
        find_all_paragraphs(key).first
        find_all_paragraphs(key).first
end
inspect() click to toggle source
# File lib/inevitable_cacophony/parser/sectioned_text.rb, line 55
def inspect
        "<SectionedText: #{@sections.inspect}>"
end