Class: Komonjo::Model::PartialMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/komonjo/models/partial_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, filters) ⇒ PartialMessage

Returns a new instance of PartialMessage.



9
10
11
12
13
14
# File 'lib/komonjo/models/partial_message.rb', line 9

def initialize(text, filters)
  @text = text
  @markdown = text
  @filters = filters
  parse
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



7
8
9
# File 'lib/komonjo/models/partial_message.rb', line 7

def filters
  @filters
end

#markdownObject

Returns the value of attribute markdown.



5
6
7
# File 'lib/komonjo/models/partial_message.rb', line 5

def markdown
  @markdown
end

#nextObject

Returns the value of attribute next.



4
5
6
# File 'lib/komonjo/models/partial_message.rb', line 4

def next
  @next
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/komonjo/models/partial_message.rb', line 6

def text
  @text
end

Instance Method Details

#embedObject



52
53
# File 'lib/komonjo/models/partial_message.rb', line 52

def embed(*)
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

#typeObject



48
49
50
# File 'lib/komonjo/models/partial_message.rb', line 48

def type
  :text
end