class Syobocal::Comment::Element::TextNode
Constants
- ENCODED_SEPARATOR
- SUBJECT_SEPARATOR
Attributes
text_elements[R]
Public Class Methods
match?(line)
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 37 def self.match?(line) true end
new(text_elements)
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 10 def initialize(text_elements) @text_elements = text_elements end
parse(text)
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 41 def self.parse(text) elements = text.split(/(\[\[[^\[\]]*?\]\])/).select { |s| !s.empty? }.map do |s| if s.match(/\A\[\[[^\[\]]*?\]\]\Z/) Link.create(s) else Text.create(s) end end Element::TextNode.new(elements) end
Public Instance Methods
==(other)
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 18 def ==(other) other.instance_of?(self.class) && other.text_elements == text_elements end
inner_text()
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 14 def inner_text text_elements.map(&:str).join("") end
split()
click to toggle source
# File lib/syobocal/comment/element/text_node.rb, line 22 def split buffer = "" text_elements.each do |node| case node when Element::Text buffer << node.str.gsub(SUBJECT_SEPARATOR, ENCODED_SEPARATOR) when Element::Link buffer << node.str end end buffer.scan(/[^#{ENCODED_SEPARATOR}\(]+(?:\(.*?\))?/).map { |str| str.gsub(ENCODED_SEPARATOR, SUBJECT_SEPARATOR).strip } end