Class: SiriCal::SayProxy
- Inherits:
-
Object
- Object
- SiriCal::SayProxy
- Defined in:
- lib/siri_cal/say_proxy.rb
Class Method Summary collapse
- .<<(say) ⇒ Object
- .all ⇒ Object
- .clear ⇒ Object
- .count ⇒ Object
- .invoke_say(event, object = nil) ⇒ Object
-
.load_files ⇒ Object
Internal : Load only once Siri says files.
- .matches_says(name) ⇒ Object
- .proxy ⇒ Object
Class Method Details
.<<(say) ⇒ Object
17 18 19 |
# File 'lib/siri_cal/say_proxy.rb', line 17 def <<(say) proxy << say end |
.all ⇒ Object
57 58 59 |
# File 'lib/siri_cal/say_proxy.rb', line 57 def all proxy end |
.clear ⇒ Object
41 42 43 |
# File 'lib/siri_cal/say_proxy.rb', line 41 def clear proxy.clear end |
.count ⇒ Object
21 22 23 |
# File 'lib/siri_cal/say_proxy.rb', line 21 def count proxy.count end |
.invoke_say(event, object = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/siri_cal/say_proxy.rb', line 29 def invoke_say(event, object=nil) matches = matches_says(event.title) raise RedundantError, "You should have only one say step that matches \"#{name}\"" if matches.size > 1 if !matches.empty? m = matches.first @object, @event = object, event self.instance_exec(*m.captures, &m.block) return true end false end |
.load_files ⇒ Object
Internal : Load only once Siri says files
Returns true on success Returns false if already loaded
49 50 51 52 53 54 55 |
# File 'lib/siri_cal/say_proxy.rb', line 49 def load_files return false unless proxy.empty? Dir.glob(File.join(SiriCal.siri_says_path, "*")).each do |filename| load File.(filename) end true end |
.matches_says(name) ⇒ Object
25 26 27 |
# File 'lib/siri_cal/say_proxy.rb', line 25 def matches_says(name) proxy.select { |say| !!(say.regexp =~ name and say.captures = $~.captures) } end |
.proxy ⇒ Object
13 14 15 |
# File 'lib/siri_cal/say_proxy.rb', line 13 def proxy @proxy ||= [] end |