Module: FlowChat::Meta::ChoiceLadder

Defined in:
lib/flow_chat/meta/choice_ladder.rb

Overview

Which interactive surface renders a given number of choices.

The renderer and the choice mapper both need this answer, and they must agree: the renderer decides what the user sees, the mapper decides what a reply is allowed to mean. Two copies of the arithmetic would drift into a screen whose replies cannot be resolved.

Class Method Summary collapse

Class Method Details

The carousel holds elements, each holding buttons, and one option is one button.



20
21
22
# File 'lib/flow_chat/meta/choice_ladder.rb', line 20

def self.carousel_capacity(limits)
  limits.max_carousel_elements * limits.max_buttons_per_element
end

.numbers_in_body?(count, limits, always_number: false) ⇒ Boolean

Whether the options are also listed, numbered, in the message body.

always_number is for platforms whose interactive surfaces do not render everywhere. Without it a user who cannot see the buttons has no way to answer at all.

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/flow_chat/meta/choice_ladder.rb', line 29

def self.numbers_in_body?(count, limits, always_number: false)
  return false if count.zero?
  return true if always_number

  rung_for(count, limits) == :numbered
end

.rung_for(count, limits) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/flow_chat/meta/choice_ladder.rb', line 10

def self.rung_for(count, limits)
  return :none if count.zero?
  return :quick_replies if count <= limits.max_quick_replies
  return :carousel if count <= carousel_capacity(limits)

  :numbered
end