class Komonjo::Model::PartialMessage

Attributes

filters[RW]
markdown[RW]
next[RW]
text[RW]

Public Class Methods

new(text, filters) click to toggle source
# File lib/komonjo/models/partial_message.rb, line 9
def initialize(text, filters)
  @text = text
  @markdown = text
  @filters = filters
  parse
end

Public Instance Methods

embed(*) click to toggle source
# File lib/komonjo/models/partial_message.rb, line 52
def embed(*)
end
parse() click to toggle source
# File lib/komonjo/models/partial_message.rb, line 16
def parse
  f = filters.find { |e| e.match(text) }
  return unless f
  arr = f.parse(text)
  case arr.size
  when 1
    a, = arr
    @text = a[:text]
    extend f.mixin
  when 2
    a, b = arr
    @text = a[:text]
    if a[:matched]
      extend f.mixin
      @next = PartialMessage.new(b[:text], filters)
      @next.parse
    else
      @next = PartialMessage.new(b[:text], filters).tap do |e|
        e.extend f.mixin
      end
    end
  when 3
    a, b, c = arr
    @text = a[:text]
    @next = PartialMessage.new(b[:text], filters).tap do |e|
      e.extend f.mixin
      e.next = PartialMessage.new(c[:text], filters).tap(&:parse)
    end
  end
  self
end
type() click to toggle source
# File lib/komonjo/models/partial_message.rb, line 48
def type
  :text
end