Class: Netposti::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/netposti/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Message

Returns a new instance of Message.



4
5
6
# File 'lib/netposti/message.rb', line 4

def initialize(message)
  @message = message
end

Instance Method Details

#attachment_urlObject



20
21
22
23
24
# File 'lib/netposti/message.rb', line 20

def attachment_url
  pdf_icon_value = @message.search('.small-pdf-icon').first.attributes['onclick'].value
  download_path = pdf_icon_value.match(/window.location.href='.(.*?)'/)[1].split('-', 2).last
  @message.uri.to_s + '-' + download_path
end

#dateObject



12
13
14
# File 'lib/netposti/message.rb', line 12

def date
  @message.search('#message-detail-header-content .date').text
end

#download_attachment(filename = nil) ⇒ Object



26
27
28
# File 'lib/netposti/message.rb', line 26

def download_attachment(filename = nil)
  @message.mech.get(attachment_url).save(filename)
end

#senderObject



8
9
10
# File 'lib/netposti/message.rb', line 8

def sender
  @message.search('#message-detail-header-content .sender').text
end

#subjectObject



16
17
18
# File 'lib/netposti/message.rb', line 16

def subject
  @message.form.field_with(:name => 'messageSubjectTextField').value
end

#to_hashObject



30
31
32
33
34
35
36
37
# File 'lib/netposti/message.rb', line 30

def to_hash
  {
    sender: sender,
    date: date,
    subject: subject,
    attachment_url: attachment_url
  }
end

#to_sObject



39
40
41
# File 'lib/netposti/message.rb', line 39

def to_s
  "#{date}: #{sender} - #{subject}"
end