Class: SpreeCmCommissioner::InviteGuestClaimedTelegramMessageFactory

Inherits:
TelegramMessageFactory show all
Defined in:
app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb

Instance Attribute Summary collapse

Attributes inherited from TelegramMessageFactory

#subtitle, #title

Instance Method Summary collapse

Methods inherited from TelegramMessageFactory

#bold, #footer, #header, #inline_code, #italic, #message, #parse_mode, #pretty_date

Constructor Details

#initialize(title:, order:, guest:, **options) ⇒ InviteGuestClaimedTelegramMessageFactory

Returns a new instance of InviteGuestClaimedTelegramMessageFactory.



20
21
22
23
24
25
26
27
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 20

def initialize(title:, order:, guest:, **options)
  @order = order
  @vendor = options[:vendor]
  @guest = guest
  @show_details_link = options[:show_details_link] || false

  super(title: title, subtitle: options[:subtitle])
end

Instance Attribute Details

#guestObject (readonly)

Returns the value of attribute guest.



18
19
20
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 18

def guest
  @guest
end

#orderObject (readonly)

Returns the value of attribute order.



18
19
20
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 18

def order
  @order
end

Returns the value of attribute show_details_link.



18
19
20
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 18

def show_details_link
  @show_details_link
end

#vendorObject (readonly)

Returns the value of attribute vendor.



18
19
20
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 18

def vendor
  @vendor
end

Instance Method Details

#bodyObject

override



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 36

def body
  text = []
  text << '<p>📣 --- <b>[NEW GUEST CLAIMED INVITATION]</b> ---</p>'
  text << '<p>✨ <b>Ticket Successfully Claimed!</b> ✨</p>'
  text << '<p><b>🙍 Claimed By</b><br>'
  text << "Name: #{guest.first_name} #{guest.last_name}<br>"
  text << "Tel: <code>#{guest.phone_number}</code></p>"

  selected_line_items.each do |item|
    text << line_item_block(item)
  end

  text << "<p><b>📑 Order Number:</b><br><code>#{order.number}</code></p>"

  text.join("\n")
end

#line_item_block(item) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 53

def line_item_block(item)
  parts = []
  parts << "<p><b>#{item.product.name}</b><br>"

  details = []
  details << "👉 #{item.options_text}" if item.options_text.present?
  details << pretty_date_for(item) if item.date_present?

  parts << details.map { |d| "<i>#{d}</i><br>" }.join
  parts << '</p>'
  parts.join("\n")
end

#pretty_date_for(line_item) ⇒ Object



66
67
68
69
70
71
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 66

def pretty_date_for(line_item)
  from_date = pretty_date(line_item.from_date)
  to_date = pretty_date(line_item.to_date)

  from_date == to_date ? "🗓️ #{from_date}" : "🗓️ #{from_date} -> #{to_date}"
end

#selected_line_itemsObject



29
30
31
32
33
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 29

def selected_line_items
  return order.line_items.for_vendor(vendor) if vendor.present?

  order.line_items
end