Class: SpreeCmCommissioner::TelegramMessageFactory

Inherits:
Object
  • Object
show all
Defined in:
app/factory/spree_cm_commissioner/telegram_message_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, subtitle: nil) ⇒ TelegramMessageFactory

Returns a new instance of TelegramMessageFactory.



5
6
7
8
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 5

def initialize(title:, subtitle: nil)
  @title = title
  @subtitle = subtitle
end

Instance Attribute Details

#subtitleObject (readonly)

Returns the value of attribute subtitle.



3
4
5
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 3

def subtitle
  @subtitle
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 3

def title
  @title
end

Instance Method Details

#bodyObject



25
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 25

def body; end

#bold(text) ⇒ Object



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

def bold(text)
  "<b>#{text}</b>"
end


26
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 26

def footer; end

#headerObject



21
22
23
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 21

def header
  "<b>#{title}</b>"
end

#inline_code(text) ⇒ Object



36
37
38
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 36

def inline_code(text)
  "<code>#{text}</code>"
end

#italic(text) ⇒ Object



32
33
34
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 32

def italic(text)
  "<i>#{text}</i>"
end

#messageObject



10
11
12
13
14
15
16
17
18
19
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 10

def message
  text = []

  text << header.presence
  text << subtitle.presence if subtitle.present?
  text << body.presence
  text << footer.presence

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

#parse_modeObject



40
41
42
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 40

def parse_mode
  'HTML'
end

#pretty_date(date) ⇒ Object



44
45
46
47
48
# File 'app/factory/spree_cm_commissioner/telegram_message_factory.rb', line 44

def pretty_date(date)
  return '' if date.blank?

  date.to_date.strftime('%b %d, %Y')
end