Class: SmsBackupRenderer::ConversationPage
- Defined in:
- lib/sms_backup_renderer/renderer.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns an Array of Message instances to be shown on this page.
Attributes inherited from BasePage
#assets_dir_path, #output_file_path
Class Method Summary collapse
-
.build_filename(participants) ⇒ Object
Returns a filename for a conversation page for the given participants, such as ‘123456789.html’.
Instance Method Summary collapse
-
#initialize(output_file_path, assets_dir_path, messages) ⇒ ConversationPage
constructor
A new instance of ConversationPage.
- #message_date_time_span(message, previous_message) ⇒ Object
- #sender_span(message, previous_message) ⇒ Object
- #template_name ⇒ Object
- #title ⇒ Object
Methods inherited from BasePage
#asset_path, #relative_path, #render, #write
Constructor Details
#initialize(output_file_path, assets_dir_path, messages) ⇒ ConversationPage
Returns a new instance of ConversationPage.
58 59 60 61 |
# File 'lib/sms_backup_renderer/renderer.rb', line 58 def initialize(output_file_path, assets_dir_path, ) super(output_file_path, assets_dir_path) @messages = .sort_by(&:date_time) end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns an Array of Message instances to be shown on this page.
56 57 58 |
# File 'lib/sms_backup_renderer/renderer.rb', line 56 def @messages end |
Class Method Details
.build_filename(participants) ⇒ Object
Returns a filename for a conversation page for the given participants, such as ‘123456789.html’. Should always return the same name for the same list of participants. The normalized addresses are used when they are numeric, but non-numeric addresses (such as email addresses) will be hex-encoded to avoid any problems with file name restrictions.
participants - an Array of Participant instances
Returns a String filename.
110 111 112 113 114 115 116 117 118 |
# File 'lib/sms_backup_renderer/renderer.rb', line 110 def self.build_filename(participants) participants.map do |participant| if participant.normalized_address =~ /\A\d+\z/ participant.normalized_address else '0x' + Digest.hexencode(participant.address) end end.sort.join('_') + '.html' end |
Instance Method Details
#message_date_time_span(message, previous_message) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sms_backup_renderer/renderer.rb', line 77 def (, ) formatted = if && .date_time.to_date == .date_time.to_date if .date_time.to_time - .date_time.to_time < 600 nil else .date_time.strftime('%-I:%M%P') end else .date_time.strftime('%A, %b %-d, %Y at %-I:%M%P %Z') end return '' unless formatted "<span class=\"message-date-time\">#{formatted}</span>" end |
#sender_span(message, previous_message) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sms_backup_renderer/renderer.rb', line 91 def sender_span(, ) if && .outgoing == .outgoing && (.outgoing || .sender.normalized_address == .sender.normalized_address) '' else sender = .outgoing ? 'You' : (.sender.name || .sender.normalized_address) "<span class=\"sender\">#{ERB::Util.html_escape(sender)}</span>" end end |
#template_name ⇒ Object
63 64 65 |
# File 'lib/sms_backup_renderer/renderer.rb', line 63 def template_name 'conversation.html.erb' end |
#title ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/sms_backup_renderer/renderer.rb', line 67 def title .first.participants.reject(&:owner).map do |participant| if participant.name "#{participant.name} (#{participant.normalized_address})" else participant.normalized_address end end.sort.join(', ') end |