Class: SiriCal::SayProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/siri_cal/say_proxy.rb

Class Method Summary collapse

Class Method Details

.<<(say) ⇒ Object



17
18
19
# File 'lib/siri_cal/say_proxy.rb', line 17

def <<(say)
  proxy << say
end

.allObject



57
58
59
# File 'lib/siri_cal/say_proxy.rb', line 57

def all
  proxy
end

.clearObject



41
42
43
# File 'lib/siri_cal/say_proxy.rb', line 41

def clear
  proxy.clear
end

.countObject



21
22
23
# File 'lib/siri_cal/say_proxy.rb', line 21

def count
  proxy.count
end

.invoke_say(event, object = nil) ⇒ Object

Raises:



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_filesObject

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.expand_path(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

.proxyObject



13
14
15
# File 'lib/siri_cal/say_proxy.rb', line 13

def proxy
  @proxy ||= []
end