tuomas-tweetwine 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.6 released 2009-06-07
2
+
3
+ * Improved URL highlighting.
4
+
1
5
  === 0.1.5 released 2009-06-06
2
6
 
3
7
  * URLs of http(s) scheme are highlighted. Changed colors.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  full_name = "Tweetwine"
4
4
  package_name = "tweetwine"
5
- version = "0.1.5"
5
+ version = "0.1.6"
6
6
 
7
7
  require "lib/#{package_name}"
8
8
 
data/lib/tweetwine/io.rb CHANGED
@@ -1,5 +1,15 @@
1
1
  module Tweetwine
2
2
  class IO
3
+ COLOR_CODES = {
4
+ :cyan => 36,
5
+ :green => 32,
6
+ :magenta => 35,
7
+ :yellow => 33
8
+ }
9
+
10
+ NICK_REGEX = /@\w+/
11
+ URL_REGEX = /(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(:[0-9]{2,5})?(((\/[a-z0-9_\-]+)+\/?)|(\/))?/i
12
+
3
13
  def initialize(options)
4
14
  @input = options[:input] || $stdin
5
15
  @output = options[:output] || $stdout
@@ -26,44 +36,33 @@ module Tweetwine
26
36
  end
27
37
 
28
38
  def show_statuses(statuses)
29
- statuses.each do |status|
30
- time_diff_value, time_diff_unit = Util.humanize_time_diff(status["created_at"], Time.now)
31
- from_user = status["user"]["screen_name"]
32
- from_user = colorize(:green, from_user) if @colorize
33
- in_reply_to = status["in_reply_to_screen_name"]
34
- in_reply_to = if in_reply_to && !in_reply_to.empty?
35
- in_reply_to = colorize(:green, in_reply_to) if @colorize
36
- "in reply to #{in_reply_to}, "
37
- else
38
- ""
39
- end
40
- text = status["text"]
41
- if @colorize
42
- text = colorize(:yellow, text, NICK_REGEX)
43
- text = colorize(:cyan, text, URL_REGEX)
44
- end
45
- @output.puts <<-END
46
- #{from_user}, #{in_reply_to}#{time_diff_value} #{time_diff_unit} ago:
47
- #{text}
48
-
49
- END
50
- end
39
+ statuses.each { |status| show_status(status) }
51
40
  end
52
41
 
53
42
  private
54
43
 
55
- COLOR_CODES = {
56
- :cyan => 36,
57
- :green => 32,
58
- :magenta => 35,
59
- :yellow => 33
60
- }.inject({}) do |result, pair|
61
- result[pair.first.to_sym] = "\033[#{pair.last}m"
62
- result
63
- end
44
+ def show_status(status)
45
+ time_diff_value, time_diff_unit = Util.humanize_time_diff(status["created_at"], Time.now)
46
+ from_user = status["user"]["screen_name"]
47
+ from_user = colorize(:green, from_user) if @colorize
48
+ in_reply_to = status["in_reply_to_screen_name"]
49
+ in_reply_to = if in_reply_to && !in_reply_to.empty?
50
+ in_reply_to = colorize(:green, in_reply_to) if @colorize
51
+ "in reply to #{in_reply_to}, "
52
+ else
53
+ ""
54
+ end
55
+ text = status["text"]
56
+ if @colorize
57
+ text = colorize(:yellow, text, NICK_REGEX)
58
+ text = colorize(:cyan, text, URL_REGEX)
59
+ end
60
+ @output.puts <<-END
61
+ #{from_user}, #{in_reply_to}#{time_diff_value} #{time_diff_unit} ago:
62
+ #{text}
64
63
 
65
- NICK_REGEX = /@\w+/
66
- URL_REGEX = /(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/\S*)?/i
64
+ END
65
+ end
67
66
 
68
67
  def colorize(color, str, matcher = nil)
69
68
  color_code = COLOR_CODES[color.to_sym]
@@ -76,7 +75,7 @@ module Tweetwine
76
75
  end
77
76
 
78
77
  def colorize_str(color_code, str)
79
- "#{color_code}#{str}\033[0m"
78
+ "\033[#{color_code}m#{str}\033[0m"
80
79
  end
81
80
  end
82
81
  end
data/test/io_test.rb CHANGED
@@ -134,6 +134,56 @@ Hi, \033[33m@barman\033[0m! Check this: \033[36mhttp://www.foo.com\033[0m. Nice,
134
134
  @io.show_statuses(statuses)
135
135
  end
136
136
  end
137
+
138
+ context "Nick regex" do
139
+ should "match a proper nick reference" do
140
+ assert_full_match IO::NICK_REGEX, "@nick"
141
+ assert_full_match IO::NICK_REGEX, "@nick_man"
142
+ end
143
+
144
+ should "not match an inproper nick reference" do
145
+ assert_no_full_match IO::NICK_REGEX, "@"
146
+ assert_no_full_match IO::NICK_REGEX, "nick"
147
+ assert_no_full_match IO::NICK_REGEX, "@nick-man"
148
+ end
149
+ end
150
+
151
+ context "URL regex" do
152
+ should "match an IP" do
153
+ assert_full_match IO::URL_REGEX, "http://127.0.0.1"
154
+ assert_full_match IO::URL_REGEX, "http://127.0.0.1/"
155
+ assert_full_match IO::URL_REGEX, "https://127.0.0.1"
156
+ assert_full_match IO::URL_REGEX, "https://127.0.0.1/"
157
+ end
158
+
159
+ should "match a FQDN" do
160
+ assert_full_match IO::URL_REGEX, "https://fo.com"
161
+ assert_full_match IO::URL_REGEX, "https://fo.com/"
162
+ assert_full_match IO::URL_REGEX, "http://www.foo.com"
163
+ assert_full_match IO::URL_REGEX, "http://www.foo.com/"
164
+ assert_full_match IO::URL_REGEX, "https://www.foo.com"
165
+ assert_full_match IO::URL_REGEX, "https://www.foo.com/"
166
+ end
167
+
168
+ should "respect whitespace, parentheses, periods, etc. at the end" do
169
+ assert_full_match IO::URL_REGEX, "http://tr.im/WGAP"
170
+ assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP "
171
+ assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP)"
172
+ assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP."
173
+ assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP,"
174
+ end
175
+
176
+ should "match multipart URLs" do
177
+ assert_full_match IO::URL_REGEX, "http://technomancy.us/126"
178
+ assert_full_match IO::URL_REGEX, "http://technomancy.us/126/"
179
+ assert_full_match IO::URL_REGEX, "http://bit.ly/18rUVx"
180
+ assert_full_match IO::URL_REGEX, "http://bit.ly/18rUVx/"
181
+ assert_full_match IO::URL_REGEX, "http://bit.ly/18rU_Vx"
182
+ assert_full_match IO::URL_REGEX, "http://bit.ly/18rU_Vx/"
183
+ assert_full_match IO::URL_REGEX, "http://www.ireport.com/docs/DOC-266869"
184
+ assert_full_match IO::URL_REGEX, "http://www.ireport.com/docs/DOC-266869/"
185
+ end
186
+ end
137
187
  end
138
188
 
139
189
  end
data/test/test_helper.rb CHANGED
@@ -5,3 +5,19 @@ require "shoulda"
5
5
  require "mocha"
6
6
 
7
7
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
8
+
9
+ module Test
10
+ module Unit
11
+ class TestCase
12
+ def assert_full_match(regex, str, msg = "")
13
+ match_data = regex.match(str)
14
+ assert(str == match_data.to_s, msg)
15
+ end
16
+
17
+ def assert_no_full_match(regex, str, msg = "")
18
+ match_data = regex.match(str)
19
+ assert(str != match_data.to_s, msg)
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuomas-tweetwine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-06 00:00:00 -07:00
12
+ date: 2009-06-07 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -63,7 +63,7 @@ homepage: http://github.com/tuomas/tweetwine
63
63
  post_install_message:
64
64
  rdoc_options:
65
65
  - --title
66
- - Tweetwine 0.1.5
66
+ - Tweetwine 0.1.6
67
67
  - --main
68
68
  - README.rdoc
69
69
  - --exclude