Class: MdSpell::TextLine
- Inherits:
-
Object
- Object
- MdSpell::TextLine
- Defined in:
- lib/mdspell/text_line.rb
Overview
Containing concatenated text from single document line.
Constant Summary collapse
- ELEMENT_TYPES =
Accepted types of elements.
[:text, :smart_quote].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Textual content of the element.
-
#location ⇒ Object
readonly
Line number of the element in document.
Class Method Summary collapse
-
.scan(document) ⇒ Object
Scan Kramdown::Document for TextLines.
Instance Method Summary collapse
-
#<<(element) ⇒ Object
Append Kramdown::Element’s content to this element.
-
#initialize(element) ⇒ TextLine
constructor
Create a new TextLine from Kramdown::Element object.
-
#words ⇒ Object
Return all words in this element.
Constructor Details
Instance Attribute Details
#content ⇒ Object (readonly)
Textual content of the element.
13 14 15 |
# File 'lib/mdspell/text_line.rb', line 13 def content @content end |
#location ⇒ Object (readonly)
Line number of the element in document.
10 11 12 |
# File 'lib/mdspell/text_line.rb', line 10 def location @location end |
Class Method Details
.scan(document) ⇒ Object
Scan Kramdown::Document for TextLines.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mdspell/text_line.rb', line 52 def self.scan(document) results = [] get_all_textual_elements(document.root.children).each do |element| matching_element_found = results.any? do |text_element| if text_element.location == element.[:location] text_element << element true else false end end results << TextLine.new(element) unless matching_element_found end results end |
Instance Method Details
#<<(element) ⇒ Object
Append Kramdown::Element’s content to this element.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mdspell/text_line.rb', line 33 def <<(element) TextLine.send :assert_element_type, element return self unless ELEMENT_TYPES.include? element.type return self unless element.[:location] == @location value = element.value if element.type == :smart_quote appent_quote(value) else append_text(value) end self end |
#words ⇒ Object
Return all words in this element.
26 27 28 |
# File 'lib/mdspell/text_line.rb', line 26 def words @content.scan(/[[[:alpha:]]']+/) end |