Class: FlowChat::Messenger::Renderer

Inherits:
Object
  • Object
show all
Includes:
Renderers::MarkdownSupport
Defined in:
lib/flow_chat/messenger/renderer.rb

Direct Known Subclasses

Instagram::Renderer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderers::MarkdownSupport

included, #sanitize_html, #to_html, #to_plain_text

Constructor Details

#initialize(message, choices: nil, media: nil) ⇒ Renderer

Returns a new instance of Renderer.



10
11
12
13
14
# File 'lib/flow_chat/messenger/renderer.rb', line 10

def initialize(message, choices: nil, media: nil)
  @message = message
  @choices = choices
  @media = media
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



8
9
10
# File 'lib/flow_chat/messenger/renderer.rb', line 8

def choices
  @choices
end

#mediaObject (readonly)

Returns the value of attribute media.



8
9
10
# File 'lib/flow_chat/messenger/renderer.rb', line 8

def media
  @media
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/flow_chat/messenger/renderer.rb', line 8

def message
  @message
end

Instance Method Details

#renderObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flow_chat/messenger/renderer.rb', line 16

def render
  return build_attachment if media && choices.blank?

  result = case FlowChat::Meta::ChoiceLadder.rung_for(choice_count, limits)
  when :none then build_text
  when :quick_replies then build_quick_replies
  when :carousel then build_carousel
  when :numbered then build_text
  end

  attach_media(result)
end