Class: LOLastfm::Checker
- Inherits:
-
Object
show all
- Defined in:
- lib/LOLastfm/checker.rb
Defined Under Namespace
Classes: Settings
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(fm, name, settings = nil, &block) ⇒ Checker
Returns a new instance of Checker.
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/LOLastfm/checker.rb', line 37
def initialize (fm, name, settings = nil, &block)
raise LocalJumpError, 'no block given' unless block
@fm = fm
@name = name
@settings = Settings.new(self, settings || {})
@block = block
@timers = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/LOLastfm/checker.rb', line 52
def method_missing (id, *args, &block)
if @fm.respond_to? id
return @fm.__send__ id, *args, &block
end
super
end
|
Instance Attribute Details
#fm ⇒ Object
Returns the value of attribute fm.
35
36
37
|
# File 'lib/LOLastfm/checker.rb', line 35
def fm
@fm
end
|
#name ⇒ Object
Returns the value of attribute name.
35
36
37
|
# File 'lib/LOLastfm/checker.rb', line 35
def name
@name
end
|
#settings ⇒ Object
Returns the value of attribute settings.
35
36
37
|
# File 'lib/LOLastfm/checker.rb', line 35
def settings
@settings
end
|
Instance Method Details
#clear_timeout(what) ⇒ Object
Also known as:
clear_interval
104
105
106
107
108
|
# File 'lib/LOLastfm/checker.rb', line 104
def clear_timeout (what)
EM.schedule {
EM.cancel_timer(what)
}
end
|
#hint(*args, &block) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/LOLastfm/checker.rb', line 80
def hint (*args, &block)
if block
@hint_block = block
else
@hint_block.call(*args) if @hint_block
end
end
|
#respond_to_missing?(id) ⇒ Boolean
48
49
50
|
# File 'lib/LOLastfm/checker.rb', line 48
def respond_to_missing? (id)
@fm.respond_to?(id)
end
|
#set_interval(*args, &block) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/LOLastfm/checker.rb', line 96
def set_interval (*args, &block)
EM.schedule {
EM.add_periodic_timer(*args, &block).tap {|timer|
@timers << timer
}
}
end
|
#set_timeout(*args, &block) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/LOLastfm/checker.rb', line 88
def set_timeout (*args, &block)
EM.schedule {
EM.add_timer(*args, &block).tap {|timer|
@timers << timer
}
}
end
|
#start ⇒ Object
60
61
62
|
# File 'lib/LOLastfm/checker.rb', line 60
def start
instance_eval &@block
end
|
#stop(&block) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/LOLastfm/checker.rb', line 64
def stop (&block)
if block
@stop_block = block
else
@stopped = true
@timers.each {|timer|
clear_timeout(timer)
}
@stop_block.call if @stop_block
end
end
|
#stopped? ⇒ Boolean
78
|
# File 'lib/LOLastfm/checker.rb', line 78
def stopped?; !!@stopped; end
|