earthquake 0.2.4 → 0.2.5
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/README.md +14 -1
- data/VERSION +1 -1
- data/earthquake.gemspec +1 -1
- data/lib/earthquake/output.rb +25 -18
- metadata +1 -1
data/README.md
CHANGED
@@ -69,7 +69,7 @@ The blue is excluded.
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
####
|
72
|
+
#### Handling the command args:
|
73
73
|
|
74
74
|
Earthquake.init do
|
75
75
|
command :hi do |m|
|
@@ -88,6 +88,19 @@ The 'm' is a MatchData.
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
### Handling outputs
|
92
|
+
|
93
|
+
#### Favorites notifier:
|
94
|
+
|
95
|
+
Earthquake.init do
|
96
|
+
output do |item|
|
97
|
+
case item["event"]
|
98
|
+
when "favorite"
|
99
|
+
notify "[favorite] #{item["source"]["screen_name"]} => #{item["target"]["screen_name"]} : #{item["target_object"]["text"]}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
91
104
|
TODO
|
92
105
|
----
|
93
106
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/earthquake.gemspec
CHANGED
data/lib/earthquake/output.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Earthquake
|
3
3
|
module Output
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def outputs
|
5
|
+
@outputs ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def output(&block)
|
9
|
+
if block
|
10
|
+
outputs << block
|
11
|
+
else
|
12
|
+
return if item_queue.empty?
|
13
|
+
insert do
|
14
|
+
while item = item_queue.shift
|
15
|
+
item["hide_timestamp"] = true
|
16
|
+
puts_items(item)
|
17
|
+
end
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
13
22
|
def puts_items(items)
|
14
23
|
[items].flatten.each do |item|
|
15
|
-
|
24
|
+
outputs.each do |p|
|
16
25
|
begin
|
17
26
|
p.call(item)
|
18
27
|
rescue => e
|
@@ -22,14 +31,6 @@ module Earthquake
|
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
def output_handers
|
26
|
-
@output_handers ||= []
|
27
|
-
end
|
28
|
-
|
29
|
-
def output_hander(&block)
|
30
|
-
output_handers << block
|
31
|
-
end
|
32
|
-
|
33
34
|
def insert(*messages)
|
34
35
|
clear_line
|
35
36
|
puts messages unless messages.empty?
|
@@ -52,11 +53,11 @@ module Earthquake
|
|
52
53
|
end
|
53
54
|
|
54
55
|
init do
|
55
|
-
|
56
|
+
outputs.clear
|
56
57
|
|
57
58
|
config[:colors] ||= (31..36).to_a + (91..96).to_a
|
58
59
|
|
59
|
-
|
60
|
+
output do |item|
|
60
61
|
next unless item["text"]
|
61
62
|
|
62
63
|
if item["in_reply_to_status_id"]
|
@@ -66,19 +67,25 @@ module Earthquake
|
|
66
67
|
else
|
67
68
|
misc = ""
|
68
69
|
end
|
70
|
+
|
71
|
+
statuses = ["[#{item["id"].to_s}]"]
|
72
|
+
unless item["hide_timestamp"]
|
73
|
+
statuses.insert(0, "[#{Time.parse(item["created_at"]).strftime('%Y.%m.%d %X')}]")
|
74
|
+
end
|
75
|
+
|
69
76
|
source = item["source"] =~ />(.*)</ ? $1 : 'web'
|
70
77
|
user_color = color_of(item["user"]["screen_name"])
|
71
78
|
text = item["text"].e.gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
|
72
79
|
c = color_of($1)
|
73
80
|
"<#{c}>#{i}</#{c}>"
|
74
81
|
end
|
75
|
-
status = "<90
|
82
|
+
status = "<90>#{statuses.join(" ").e}</90> " +
|
76
83
|
"<#{user_color}>#{item["user"]["screen_name"].e}</#{user_color}>: " +
|
77
84
|
"#{text}<90>#{misc.e} #{source.e}</90>"
|
78
85
|
puts status.t
|
79
86
|
end
|
80
87
|
|
81
|
-
|
88
|
+
output do |item|
|
82
89
|
next unless item["event"]
|
83
90
|
|
84
91
|
case item["event"]
|