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.



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

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.



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

def guest
  @guest
end

#orderObject (readonly)

Returns the value of attribute order.



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

def order
  @order
end

Returns the value of attribute show_details_link.



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

def show_details_link
  @show_details_link
end

#vendorObject (readonly)

Returns the value of attribute vendor.



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

def vendor
  @vendor
end

Instance Method Details

#bodyObject

override



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

def body
  text = []

  text << bold('🙍 Claimed By')
  text << "Name: #{guest.first_name} #{guest.last_name}"
  text << "Tel: #{inline_code(guest.phone_number)}"
  text << ''

  # Each invitation_link leads to one order with one line_item, claimed by one guest so quantity is always 1.
  selected_line_items.each do |item|
    text << bold(item.product.name.to_s)
    text << '🎟️ Quantity: 1'
    text << italic("👉 #{item.options_text}") if item.options_text.present?
    text << italic(pretty_date_for(item)) if item.date_present?
    text << ''
  end

  text << bold('Order Number:')
  text << inline_code(order.number)

  text.compact.join("\n")
end

#pretty_date_for(line_item) ⇒ Object



56
57
58
59
60
61
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 56

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



28
29
30
# File 'app/factory/spree_cm_commissioner/invite_guest_claimed_telegram_message_factory.rb', line 28

def selected_line_items
  vendor.present? ? order.line_items.for_vendor(vendor) : order.line_items
end