• R/O
  • SSH
  • HTTPS

tsubuyakiticker: コミット


コミットメタ情報

リビジョン18 (tree)
日時2013-03-24 13:31:48
作者mshio

ログメッセージ

add HashUtil and rename ListLauncher

変更サマリ

差分

--- tsubuyakiticker/src/listManager.coffee (revision 17)
+++ tsubuyakiticker/src/listManager.coffee (nonexistent)
@@ -1,37 +0,0 @@
1-class ListManager
2- constructor: (@numUser, _public) ->
3- @_ = _public
4- @counter = 0
5- @timer = new TickerTimer this, 'execCheck', 10
6- @writer = _public.tickerDomWriter
7- @setting = _public.setting
8-
9- check: ->
10- data = @_.tickerData
11- list = data.tweetList
12- num = data.tweetNum
13- failure = data.failure
14- failureCount = (->
15- r = 0
16- for k, v of failure
17- r++ if v
18- return r)()
19-
20- size = 0
21- size++ for k, t of list
22- return false if size != @numUser - failureCount
23- i = 0
24- for k, t of list
25- return false if t.length != num[k]
26- data.failure[k] = false for k, t of failure
27- return true
28-
29- execCheck: ->
30- if ! this.check()
31- if ++@counter < 200
32- @timer.restart 10
33- else
34- @writer.generateList @setting.responseFailureMessage
35- else
36- @writer.cleanupScript()
37- @writer.generateList null
--- tsubuyakiticker/src/tickerData.coffee (revision 17)
+++ tsubuyakiticker/src/tickerData.coffee (revision 18)
@@ -1,3 +1,15 @@
1+# -*- conding: utf-8 -*-
2+
3+# Manages informations used by the ticker
4+#
5+# - userList: an array of twitter account names
6+# - failure:
7+# - tweetList: a hash of tweets. its keys are
8+# twitter account names
9+# - tweetNum: a hash of number of tweets.
10+# - animation:
11+# - dateFormatter:
12+#
113 class TickerData
214 constructor: (setting) ->
315 @userList = this._makeUserListFrom setting
--- tsubuyakiticker/src/listLauncher.coffee (nonexistent)
+++ tsubuyakiticker/src/listLauncher.coffee (revision 18)
@@ -0,0 +1,39 @@
1+# -*- coding: utf-8 -*-
2+
3+# an object to check if having failed to get tweets and
4+# to make a ticker-writer generate tweets lists.
5+#
6+class ListLauncher
7+ constructor: (@numUser, _public) ->
8+ @counter = 0
9+ @timer = new TickerTimer this, 'go', 10
10+ @writer = _public.tickerDomWriter
11+ @setting = _public.setting
12+ @data = _public.tickerData
13+
14+ check: ->
15+ list = @data.tweetList
16+ return false if ! this._checkUserLength list
17+ return false if ! this._checkTweetLength list
18+
19+ return true
20+
21+ _checkUserLength: (tweetList) ->
22+ size = @numUser - (new HashUtil @data.failure).size true
23+ return size is (new HashUtil tweetList).size()
24+
25+ _checkTweetLength: (tweetList) ->
26+ for k, t of tweetList
27+ return false if t.length != @data.tweetNum[k]
28+ @data.failure[k] = false for k, t of @data.failure
29+ return true
30+
31+ go: ->
32+ if ! this.check()
33+ if ++@counter < 200
34+ @timer.restart 10
35+ else
36+ @writer.generateList @setting.responseFailureMessage
37+ else
38+ @writer.cleanupScript()
39+ @writer.generateList()
--- tsubuyakiticker/src/tickerDomWriter.coffee (revision 17)
+++ tsubuyakiticker/src/tickerDomWriter.coffee (revision 18)
@@ -19,7 +19,7 @@
1919 cleanupAllTweetElement: ->
2020 nds = @target.childNodes[0].innerHTML = ''
2121
22- generateList: (errorMessage) ->
22+ generateList: (errorMessage=null) ->
2323 nodes = this._listNodes errorMessage
2424 d = @target.childNodes[0]
2525 if d.childNodes.length > 0
--- tsubuyakiticker/src/tickerAnimation.coffee (revision 17)
+++ tsubuyakiticker/src/tickerAnimation.coffee (revision 18)
@@ -36,4 +36,4 @@
3636 @_public.tickerDomWriter.cleanupScript()
3737 c = new TweetCollector @target, @_public
3838 c.setCaller l[i], n, c._numberCode i for i in [0...l.length]
39- new ListManager l.length, @_public
39+ new ListLauncher l.length, @_public
--- tsubuyakiticker/src/hashUtil.coffee (nonexistent)
+++ tsubuyakiticker/src/hashUtil.coffee (revision 18)
@@ -0,0 +1,13 @@
1+class HashUtil
2+ constructor: (@hash) ->
3+
4+ size: (presentOnly=false) ->
5+ size = 0
6+ for k, v of @hash
7+ size++ if ! presentOnly or v
8+ return size
9+
10+ keys: ->
11+ keys = []
12+ keys.push k for k, v of @hash
13+ return keys
--- tsubuyakiticker/src/tsubuyakiTicker.coffee (revision 17)
+++ tsubuyakiticker/src/tsubuyakiTicker.coffee (revision 18)
@@ -1,7 +1,5 @@
1-_pub = null
2-
31 tweets = (result, code) ->
4- d = window.TsubuyakiTicker.tickerData
2+ d = _pub.tickerData
53 r = result.results
64 if r.length > 0
75 d.tweetList[r[0].from_user] = []
@@ -21,24 +19,23 @@
2119 b = new TickerDomBuilder target, browser
2220 b.addNoWrapElement()
2321
24- _pub = window.TsubuyakiTicker
25-
2622 _pub.tickerDomWriter = new TickerDomWriter target, _pub
2723
2824 c = new TweetCollector target, _pub
2925 c.collect()
3026
31- new ListManager _pub.tickerData.userList.length, _pub
27+ new ListLauncher _pub.tickerData.userList.length, _pub
3228
29+tsubuyakiTicker = (setting) ->
30+ _pub.tweets = tweets
31+ _pub.callbacks = {}
32+ _pub.setting = new TickerSetting setting
33+ _pub.tickerData = new TickerData _pub.setting
34+
35+_pub = if window then (window.TsubuyakiTicker = tsubuyakiTicker) else {}
36+
3337 # main --
3438 if window
35- window.TsubuyakiTicker = (setting) ->
36- _pub = window.TsubuyakiTicker
37- _pub.tweets = tweets
38- _pub.callbacks = {}
39- _pub.setting = new TickerSetting setting
40- _pub.tickerData = new TickerData _pub.setting
41-
4239 if window.addEventListener
4340 window.addEventListener 'load', run, false
4441 else if window.attachEvent
旧リポジトリブラウザで表示