Class: IMAPToRSS::Handler::HSBC
- Inherits:
-
IMAPToRSS::Handler
- Object
- IMAPToRSS::Handler
- IMAPToRSS::Handler::HSBC
- Defined in:
- lib/imap_to_rss/handler/hsbc.rb
Overview
Handles messages from HSBC savings and HSBC credit cards
Instance Attribute Summary
Attributes inherited from IMAPToRSS::Handler
Instance Method Summary collapse
-
#handle(uids) ⇒ Object
Turns
uids
into RSS items for bank-to-bank transfers and general announcements like CC payments due or interest rate changes. - #handle_a2atransfer ⇒ Object
- #handle_alert ⇒ Object
- #handle_hsbc ⇒ Object
-
#initialize ⇒ HSBC
constructor
Selects messages with hsbc in the From header.
Methods inherited from IMAPToRSS::Handler
#add_item, #each_message, handlers, inherited, #log, #setup
Constructor Details
#initialize ⇒ HSBC
Selects messages with hsbc in the From header
11 12 13 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 11 def initialize @search = 'FROM', 'hsbc' end |
Instance Method Details
#handle(uids) ⇒ Object
Turns uids
into RSS items for bank-to-bank transfers and general announcements like CC payments due or interest rate changes.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 19 def handle(uids) uids, 'text/plain' do |uid, mail| @mail = mail @url = nil @description = nil case mail.from.first when '[email protected]' then next false unless handle_a2atransfer when '[email protected]' then next false unless handle_alert when '[email protected]' then next false unless handle_hsbc else log "Unknown From: #{mail.from.join ', '}" next false end add_item mail.subject, @description, mail.from, mail.date, @url, mail., 'HSBC' end end |
#handle_a2atransfer ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 42 def handle_a2atransfer @mail.body =~ /^Dear.*?[,:] ([ \t]*\r?\n){2,} (.*?) ([ \t]*\r?\n){2,} Sincerely,/mx return false unless $2 body = $2 body.gsub!(/[*\r]/, '') body.gsub!(/[ \t]*\n/, "\n") body = body.split(/\n\n+/).map { |para| "<p>#{para}</p>" } @description = body.join "\n\n" end |
#handle_alert ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 60 def handle_alert @mail.body =~ /^Dear.*?, ([ \t]*\r?\n){2,} (.*?) ([ \t]*\r?\n){2,}/mx return false unless $2 @description = $2 end |
#handle_hsbc ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 70 def handle_hsbc case @mail.body when /purchase exceeding/ then @mail.body =~ /Description: (.*)/ purchase = $1.strip @mail.body =~ /^Amount: \$\s+([\d.]+)/ amount = $1 @description = "<p>Your purchase of \#{purchase} was for $\#{amount} which exceeds your\nnotification limit\n DESC\n when /^Dear.*?,\n ([ \\t]*\\r?\\n){2,}\n (.*?)\n ([ \\t]*\\r?\\n){2,}/mx\n @description = $2\n end\n\n return false unless @description\nend\n" |