Skip to content

Commit fbbb674

Browse files
committed
Refactor to be in line with the github style guide.
- Move require statements outside class defs. - Use parens around defs with args. - Remove implicit calls to super - Replace offensive test fixture email.
1 parent 2bdbb5f commit fbbb674

File tree

8 files changed

+130
-98
lines changed

8 files changed

+130
-98
lines changed

lib/configuration.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Configuration < ConfigToolkit::BaseConfig
88

99
CONFIG_FILE = File.expand_path_relative_to_caller("../hatterrc")
1010

11-
def initialize config_file = CONFIG_FILE
11+
def initialize(config_file = CONFIG_FILE)
1212
reader = ConfigToolkit::KeyValueReader.new config_file
1313
load reader
1414
end

lib/mailbox/maildir_mailbox.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
class Maildir_mailbox
2-
require 'mail'
1+
require 'mail'
32

4-
def initialize maildir_path
3+
class MaildirMailbox
4+
5+
def initialize(maildir_path)
56
@maildir_path = maildir_path
67
@maildir_path = "spec/fixtures/maildir"
78
end
89

9-
def mail where={label: nil, folder: nil, from: nil, to: nil, date: nil}
10+
def mail(where={label: nil, folder: nil, from: nil, to: nil, date: nil})
1011
Mail.read(@maildir_path + "/INBOX/cur/TRAIN_00001.eml")
1112
end
1213

lib/terminal.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
require 'termbox'
2+
require 'views/mail_view'
3+
require 'views/label_view'
4+
require 'views/folder_view'
5+
16
module Termbox
27
TB_INPUT_ESCAPE = 1
38
TB_INPUT_ALT = 2
49
end
510

611
class Terminal
7-
require 'termbox'
8-
require 'views/mail_view'
9-
require 'views/label_view'
10-
require 'views/folder_view'
1112

1213
def initialize
1314
initialize_termbox
@@ -30,9 +31,9 @@ def initialize_views
3031
folder_view_location = {x0: 0, y0: 0, x1: 19, y1: 40}
3132
label_view_location = {x0: 0, y0: 41, x1: 19, y1: 79}
3233
mail_view_location = {x0: 20, y0: 0, x1: 79, y1: 79}
33-
@views = [Mail_view.new(mail_view_location),
34-
Label_view.new(label_view_location),
35-
Folder_view.new(folder_view_location)]
34+
@views = [MailView.new(mail_view_location),
35+
LabelView.new(label_view_location),
36+
FolderView.new(folder_view_location)]
3637
end
3738

3839
def initialize_termbox

lib/views/folder_view.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
class Folder_view < View
2-
3-
def initialize location
4-
super
5-
end
1+
class FolderView < View
62

73
def draw
84
draw_folders

lib/views/label_view.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
class Label_view < View
2-
3-
def initialize location
4-
super
5-
end
1+
class LabelView < View
62

73
def draw
84
draw_labels

lib/views/mail_view.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'views/view'
2+
require 'termbox'
23

3-
class Mail_view < View
4-
require 'termbox'
4+
class MailView < View
55

6-
def initialize location
6+
def initialize(location)
77
super
88
@mail = @mailbox.most_recent
99
end
@@ -23,7 +23,7 @@ def draw_borders
2323
end
2424

2525
def draw_mail
26-
from = @mail.sender
26+
from, = @mail.from
2727
subject = @mail.subject
2828
text = @mail.body.decoded
2929
x = @start_x + @Border_width + 1

lib/views/view.rb

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
require 'configuration'
2+
require 'termbox'
3+
14
class View
2-
require 'configuration'
3-
require 'termbox'
45

56
attr_reader :colors, :mailbox
67

7-
def initialize location
8+
def initialize(location)
89
@Border_width = 1
910
@start_x = location[:x0]
1011
@start_y = location[:y0]
@@ -14,7 +15,7 @@ def initialize location
1415
set_colors
1516
end
1617

17-
def draw_text text, x, y
18+
def draw_text(text, x, y)
1819
words = text.split(/\s+/)
1920
words.each do |word|
2021
if x + word.length + 1 >= @end_x
@@ -34,13 +35,13 @@ def draw_text text, x, y
3435
return y
3536
end
3637

37-
def draw_horizontal_line at
38+
def draw_horizontal_line(at)
3839
@start_x.upto(@end_x) do |x|
3940
Termbox.tb_change_cell(x, at, " ".ord, @colors[:bg], @colors[:fg])
4041
end
4142
end
4243

43-
def draw_vertical_line at
44+
def draw_vertical_line(at)
4445
@start_y.upto(@end_y) do |y|
4546
Termbox.tb_change_cell(at, y, " ".ord, @colors[:bg], @colors[:fg])
4647
end
@@ -49,13 +50,13 @@ def draw_vertical_line at
4950
private
5051

5152
# Reads the maildir format from config file. Requires the class and sets
52-
# @mailbox to mailbox/<maildir-format>_mailbox
53+
# @mailbox to mailbox/<maildir-format>Mailbox
5354
def set_mailbox
5455
config = Configuration.instance
5556
maildir_format = config.maildir_format
56-
mailbox_class = maildir_format.capitalize + "_mailbox"
57+
mailbox_class = maildir_format.capitalize + "Mailbox"
5758
class_dir = File.expand_path('../../', __FILE__) + "/mailbox"
58-
mailbox_file = File.join class_dir, mailbox_class.downcase
59+
mailbox_file = File.join class_dir, maildir_format + "_mailbox"
5960
require mailbox_file
6061
maildir_path = config.maildir
6162
@mailbox = self.class.const_get(mailbox_class).new maildir_path
+100-63
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,100 @@
1-
From [email protected] Tue Aug 27 03:56:47 2002
2-
Return-Path: <[email protected]>
3-
Delivered-To: [email protected]
4-
Received: from localhost (localhost [127.0.0.1])
5-
by phobos.labs.spamassassin.taint.org (Postfix) with ESMTP id 4451C43F99
6-
for <zzzz@localhost>; Mon, 26 Aug 2002 22:56:47 -0400 (EDT)
7-
Received: from mail.webnote.net [193.120.211.219]
8-
by localhost with POP3 (fetchmail-5.9.0)
9-
for zzzz@localhost (single-drop); Tue, 27 Aug 2002 03:56:47 +0100 (IST)
10-
Received: from smtp.easydns.com (smtp.easydns.com [205.210.42.30])
11-
by webnote.net (8.9.3/8.9.3) with ESMTP id DAA29086
12-
for <[email protected]>; Tue, 27 Aug 2002 03:57:36 +0100
13-
Received: from 218.5.132.246 (unknown [211.160.14.157])
14-
by smtp.easydns.com (Postfix) with SMTP id 7714C2C995
15-
for <[email protected]>; Mon, 26 Aug 2002 22:57:31 -0400 (EDT)
16-
Received: from 55.92.178.196 ([55.92.178.196]) by smtp-server1.cfl.rr.com with QMQP; Aug, 26 2002 10:41:10 PM +1100
17-
Received: from [46.224.35.15] by rly-xl04.mx.aol.com with smtp; Aug, 26 2002 9:33:27 PM +1200
18-
Received: from unknown (26.113.85.29) by smtp4.cyberec.com with esmtp; Aug, 26 2002 8:57:10 PM -0100
19-
Received: from [183.62.39.149] by m10.grp.snv.yahoo.com with QMQP; Aug, 26 2002 7:52:32 PM +0600
20-
From: Veronica Styles <[email protected]>
21-
22-
Cc:
23-
Subject: link to my webcam you wanted
24-
Sender: Veronica Styles <[email protected]>
25-
Mime-Version: 1.0
26-
Content-Type: text/plain; charset="iso-8859-1"
27-
Date: Mon, 26 Aug 2002 22:57:34 -0400
28-
X-Mailer: eGroups Message Poster
29-
X-Priority: 1
30-
Message-Id: <[email protected]>
31-
32-
Wanna see sexually curious teens playing with each other?
33-
34-
http://www.site-personals.com <-- click here=)
35-
36-
me and my horny girlfriends are waiting for you... we are probably eating each other out on webcam in our dormitory as ur reading this! (inbetween classes of course *wink*)
37-
38-
see you soon baby,
39-
-Veronica
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
mcmfkhcpedgetqj
63-
1+
Return-Path: [email protected]
2+
Delivery-Date: Fri Sep 13 23:14:55 2002
3+
Return-Path: <[email protected]>
4+
Received: from mindupmerchants.com ([email protected] [24.205.211.91])
5+
by lerami.lerctr.org (8.12.2/8.12.2/20020902/$Revision: 1.30 $) with ESMTP id g8E4EZE9029281
6+
for <[email protected]>; Fri, 13 Sep 2002 23:14:48 -0500 (CDT)
7+
Message-Id: <[email protected]>
8+
Received: from 192.168.0.0 by mindupmerchants.com
9+
with SMTP (MDaemon.PRO.v6.0.7.R)
10+
for <[email protected]>; Fri, 13 Sep 2002 21:13:21 -0700
11+
From: "Ben Green" <[email protected]>
12+
13+
Subject: One of a kind Money maker! Try it for free!
14+
Date: Fri, 13 Sep 2002 21:13:19 -0700
15+
X-M5MailerProjectID: 4fb0caa2-c329-4c20-b331-229e681acee3
16+
17+
MIME-Version: 1.0
18+
Content-Type: multipart/mixed;
19+
boundary="----000000000000000000000"
20+
X-Return-Path: [email protected]
21+
X-MDaemon-Deliver-To: [email protected]
22+
X-Virus-Scanned: by amavisd-milter (http://amavis.org/)
23+
X-Status:
24+
X-Keywords:
25+
26+
------000000000000000000000
27+
Content-Type: text/html;
28+
charset="iso-8859-1"
29+
Content-Transfer-Encoding: 7bit
30+
31+
<body lang=EN-US>
32+
33+
<div class=Section1>
34+
35+
36+
<p class=MsoBodyText style='text-align:justify'><b>CONSANTLY</b> being
37+
bombarded by so-called “FREE” money-making systems that teases you with limited
38+
information, and when it’s all said and done, blind-sides you by demanding your
39+
money/credit card information upfront in some slick way,<b> after-the-fact</b>!
40+
Yes, I too was as skeptical about such offers and the Internet in general with
41+
all its hype, as you probably are. Fortunate for me, my main business
42+
slowed-down (<i>I have been self-employed all my life</i>), so I looked for
43+
something to fit my lifestyle and some other way to assist me in paying my
44+
bills, without working myself to death or loosing more money; then, this
45+
proposal to try something new without any upfront investment (<i>great! because
46+
I had none</i>) interested me to click on the link provided. And I don’t regret
47+
at all that I did! I am very happy, and happy enough to recommend it to you as
48+
a system that is true to its word. I mean absolutely no upfront money. You join
49+
only if (<i>when</i>) you make money. You also get to track the results of your
50+
time and efforts instantly and updated daily! I especially liked this idea of
51+
personal control with real-time, staying informed statistics.</p>
52+
53+
<p class=MsoBodyText style='text-align:justify'><b>This system is quite simply
54+
the most logical, opened, and fair of any others that I’ve seen before. Why?
55+
Because from the start, you get all the specific facts you need to seriously
56+
consider if this is right for you.  No teasing. No grand testimonies! No
57+
kidding! Just the facts! Unlike in other programs that give you “no idea” of
58+
their overall plan before first forking over your money/credit card; or worst
59+
yet, joining and finding-out too late, after wasting valuable time trying to
60+
figure them out, this system is straightforward and informative, providing you
61+
with the two things you really must know: “<u>What’s it all about</u>?” and “<u>How
62+
does it work</u>?”. These are the ultimate deal makers or deal breakers that
63+
need to be immediately disclosed, well before discovering that maybe you don’t
64+
want to do that; by then you are “hooked” and now locked into a frustrating
65+
battle to try to get your money back! </b></p>
66+
67+
<p class=MsoBodyText style='text-align:justify'>I call this my “Platinum
68+
Choice” because it stands alone as a true, superior deal that is totally
69+
different from previously misleading, “hook-first” programs that promise lofty
70+
mega-money jackpots, but really just want your money upfront to line their own
71+
pockets! You’ve seen the headlines: “<u>Join free and Make $10,000 every week
72+
for life</u>” yeah, right!</p>
73+
74+
<p class=MsoBodyText style='text-align:justify'>I did not make millions yet,
75+
but the whole thing was launched just a few weeks ago and I am more than happy
76+
with my earnings, so far. I must tell you, I wouldn’t be able to do anything
77+
without corporate help – which was unusually thorough, timely, and motivating. </p>
78+
79+
<p class=MsoBodyText style='text-align:justify'>You have to see this in action
80+
for yourself and make up your own mind; just go to my site and fill out the
81+
form as soon as you can. You will get your own site in a few minutes. Then you
82+
are ready to try whether you can make some decent money with this system and
83+
the Internet’s explosive potential - fully loaded with hi-tech software, free
84+
corporate help, on-time member’s support and even protective safeguards! </p>
85+
86+
<p class=MsoBodyText style='text-align:justify'>Get it now, and you can call me
87+
at any time with questions. It really could help you like it is helping me to
88+
finally be able to pay my bills, and keep my free time free.  Good luck!</p>
89+
90+
<p class=MsoBodyText style='text-align:justify'><a
91+
href="http://www.mindupmerchants.com/default.asp?ID=5581">http://www.mindupmerchants.com/default.asp?ID=5581</a></p>
92+
93+
<p class=MsoBodyText style='text-align:justify'>Ben Green, (775) 322-3323 </p>
94+
95+
<p class=MsoBodyText>P.S.Free POP3 email is ofered for members now!</p>
96+
</div>
97+
98+
</body>
99+
100+
------000000000000000000000--

0 commit comments

Comments
 (0)