Class: InevitableCacophony::Parser::SectionedText
- Inherits:
-
Object
- Object
- InevitableCacophony::Parser::SectionedText
- Defined in:
- lib/inevitable_cacophony/parser/sectioned_text.rb
Constant Summary collapse
- PARAGRAPH_DELIMITER =
"\n\n"
- SENTENCE_DELIMITER =
/\.\s+/
Instance Attribute Summary collapse
-
#sections ⇒ Object
Returns the value of attribute sections.
Instance Method Summary collapse
-
#find(key) ⇒ String
Find a section (paragraph, sentence, etc.) of the description matching a given regular expression.
-
#find_all(key) ⇒ Array<String>
Find all sections matching a given key.
-
#find_all_paragraphs(key) ⇒ Array<SectionedText>
As above but finds all matching paragraphs.
-
#find_paragraph(key) ⇒ SectionedText
Find a paragraph within the description, and break it up into sentences.
-
#initialize(description, delimiter = PARAGRAPH_DELIMITER) ⇒ SectionedText
constructor
A new instance of SectionedText.
- #inspect ⇒ Object
Constructor Details
#initialize(description, delimiter = PARAGRAPH_DELIMITER) ⇒ SectionedText
Returns a new instance of SectionedText.
17 18 19 |
# File 'lib/inevitable_cacophony/parser/sectioned_text.rb', line 17 def initialize(description, delimiter=PARAGRAPH_DELIMITER) @sections = description.split(delimiter).map(&:strip) end |
Instance Attribute Details
#sections ⇒ Object
Returns the value of attribute sections.
21 22 23 |
# File 'lib/inevitable_cacophony/parser/sectioned_text.rb', line 21 def sections @sections end |
Instance Method Details
#find(key) ⇒ String
Find a section (paragraph, sentence, etc.) of the description matching a given regular expression.
27 28 29 |
# File 'lib/inevitable_cacophony/parser/sectioned_text.rb', line 27 def find(key) find_all(key).first end |
#find_all(key) ⇒ Array<String>
Find all sections matching a given key
34 35 36 |
# 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) ⇒ Array<SectionedText>
As above but finds all matching paragraphs.
49 50 51 52 53 |
# 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) ⇒ SectionedText
Find a paragraph within the description, and break it up into sentences.
41 42 43 44 |
# 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 ⇒ Object
55 56 57 |
# File 'lib/inevitable_cacophony/parser/sectioned_text.rb', line 55 def inspect "<SectionedText: #{@sections.inspect}>" end |