Class: Playbook::PbMessage::Message

Inherits:
Playbook::PbKit::Base show all
Defined in:
app/pb_kits/playbook/pb_message/message.rb

Constant Summary collapse

PROPS =
%i[configured_avatar
configured_classname
configured_data
configured_id
configured_label
configured_message
configured_timestamp].freeze

Instance Method Summary collapse

Methods inherited from Playbook::PbKit::Base

#adjusted_value, #aria, #classname, #concat_value, #data, #default_value, #false_value, #id, #is_boolean?, #is_integer?, #is_set?, #is_string?, #is_true?, #merge_value, #one_of?, #one_of_value, #true_value

Constructor Details

#initialize(avatar: default_configuration, classname: default_configuration, data: default_configuration, id: default_configuration, label: default_configuration, message: default_configuration, timestamp: default_configuration) ⇒ Message

Returns a new instance of Message.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/pb_kits/playbook/pb_message/message.rb', line 14

def initialize(avatar: default_configuration,
               classname: default_configuration,
               data: default_configuration,
               id: default_configuration,
               label: default_configuration,
               message: default_configuration,
               timestamp: default_configuration)
  self.configured_avatar = avatar
  self.configured_classname = classname
  self.configured_data = data
  self.configured_id = id
  self.configured_label = label
  self.configured_message = message
  self.configured_timestamp = timestamp
end

Instance Method Details

#avatarObject



30
31
32
33
34
35
36
# File 'app/pb_kits/playbook/pb_message/message.rb', line 30

def avatar
  if is_set? configured_avatar
    configured_avatar[:size] = "sm"
    pb_avatar = Playbook::PbAvatar::Avatar.new(configured_avatar)
    ApplicationController.renderer.render(partial: pb_avatar, as: :object)
  end
end

#avatar_classObject



38
39
40
# File 'app/pb_kits/playbook/pb_message/message.rb', line 38

def avatar_class
  "avatar" if is_set? configured_avatar
end

#kit_classObject



67
68
69
70
71
72
73
# File 'app/pb_kits/playbook/pb_message/message.rb', line 67

def kit_class
  kit_options = [
    "pb_message_kit",
    avatar_class,
  ]
  kit_options.compact.join("_")
end

#labelObject



42
43
44
45
46
47
48
# File 'app/pb_kits/playbook/pb_message/message.rb', line 42

def label
  if is_set? configured_label
    caption_props = { text: configured_label }
    pb_label = Playbook::PbCaption::Caption.new(caption_props)
    ApplicationController.renderer.render(partial: pb_label, as: :object)
  end
end

#messageObject



50
51
52
53
54
55
56
57
# File 'app/pb_kits/playbook/pb_message/message.rb', line 50

def message
  if is_set? configured_message
    pb_message = Playbook::PbBody::Body.new(classname: "message_text") do
      configured_message
    end
    ApplicationController.renderer.render(partial: pb_message, as: :object)
  end
end

#timestampObject



59
60
61
62
63
64
65
# File 'app/pb_kits/playbook/pb_message/message.rb', line 59

def timestamp
  if is_set? configured_timestamp
    timestamp_props = { text: configured_timestamp }
    pb_timestamp = Playbook::PbTimestamp::Timestamp.new(timestamp_props)
    ApplicationController.renderer.render(partial: pb_timestamp, as: :object)
  end
end

#to_partial_pathObject



75
76
77
# File 'app/pb_kits/playbook/pb_message/message.rb', line 75

def to_partial_path
  "pb_message/message"
end