Module: IMExporter::Message

Defined in:
lib/im_exporter/message.rb

Overview

A module to handle messages from the iMessage sqlite database

Class Method Summary collapse

Class Method Details

.is_an_attachment?(message) ⇒ Boolean

checks whether the iMessage is actually an attachment (image)

Returns:

  • (Boolean)


42
43
44
# File 'lib/im_exporter/message.rb', line 42

def self.is_an_attachment?(message)
  if message.eql? 1 then true else false end
end

.is_from_me?(message) ⇒ Boolean

checks whether an iMessage is from yourself

Returns:

  • (Boolean)


37
38
39
# File 'lib/im_exporter/message.rb', line 37

def self.is_from_me?(message)
  if message.eql? 1 then true else false end
end

.read(id) ⇒ Object

gets metadata about each iMessage



17
18
19
20
21
# File 'lib/im_exporter/message.rb', line 17

def self.read(id)
  select_rows = 'is_from_me, text, cache_has_attachments, rowid, cache_roomnames'
  query = "select #{select_rows} from message where handle_id= ?"
  $chat_db.execute(query, id)
end

.write(user, message, file_name, file_type) ⇒ Object

writes the iMessage to a PDF or TXT document



6
7
8
9
10
11
12
13
14
# File 'lib/im_exporter/message.rb', line 6

def self.write(user, message, file_name, file_type)
  if file_type.eql? 'PDF'
    $pdf.font('/Library/Fonts/Times New Roman.ttf') do
      $pdf.text "#{user}: #{message}"
    end
  else
    File.open("#{file_name}.txt", 'a') { |file| file.write("#{user}: #{message}\n") }
  end
end

.write_logic(message_row, contact_name, file_type) ⇒ Object

the logic behind how things get written to the document



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/im_exporter/message.rb', line 24

def self.write_logic(message_row, contact_name, file_type)
  if self.is_an_attachment?(message_row[2])
    IMExporter::Attachment.write(message_row[3]) if file_type.eql? 'PDF'
  else
    if self.is_from_me?(message_row[0])
      self.write('me', message_row[1], contact_name, file_type)
    else
      self.write(contact_name, message_row[1], contact_name, file_type)
    end
  end if message_row[4].nil?
end