Class: HatebuWatcher::Counter
- Inherits:
-
Object
- Object
- HatebuWatcher::Counter
- Includes:
- Observable
- Defined in:
- lib/hatebu_watcher/counter.rb
Constant Summary collapse
- ENDPOINT =
'http://b.hatena.ne.jp/entry/jsonlite/?url='
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
-
#initialize(url) ⇒ Counter
constructor
A new instance of Counter.
- #reload ⇒ Object
Constructor Details
#initialize(url) ⇒ Counter
Returns a new instance of Counter.
13 14 15 |
# File 'lib/hatebu_watcher/counter.rb', line 13 def initialize(url) @url = url end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
11 12 13 |
# File 'lib/hatebu_watcher/counter.rb', line 11 def count @count end |
Instance Method Details
#reload ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hatebu_watcher/counter.rb', line 17 def reload @prev_count = @count @count = JSON.parse(json.read)['count'].to_i unless @count == @prev_count changed notify_observers(@count) end self end |