Class: HatebuWatcher::Counter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#countObject (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

#reloadObject



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