earthquake 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -69,7 +69,7 @@ The blue is excluded.
69
69
  end
70
70
  end
71
71
 
72
- #### Handle the command args:
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.4
1
+ 0.2.5
data/earthquake.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{earthquake}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
@@ -1,18 +1,27 @@
1
1
  # encoding: UTF-8
2
2
  module Earthquake
3
3
  module Output
4
- def output
5
- return if item_queue.empty?
6
- insert do
7
- while item = item_queue.shift
8
- puts_items(item)
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
- output_handers.each do |p|
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
- output_handers.clear
56
+ outputs.clear
56
57
 
57
58
  config[:colors] ||= (31..36).to_a + (91..96).to_a
58
59
 
59
- output_hander do |item|
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>[#{item["id"].to_s.e}]</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
- output_hander do |item|
88
+ output do |item|
82
89
  next unless item["event"]
83
90
 
84
91
  case item["event"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earthquake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo