Class: Cora

Inherits:
Object
  • Object
show all
Defined in:
lib/cora.rb,
lib/cora/version.rb

Defined Under Namespace

Classes: Location, Plugin

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/cora.rb', line 7

def location
  @location
end

Instance Method Details

#log(text) ⇒ Object



59
60
61
# File 'lib/cora.rb', line 59

def log(text)
  $stderr.puts(text) if defined?(LOG)
end

#no_matchesObject



39
40
# File 'lib/cora.rb', line 39

def no_matches
end

#pluginsObject



9
10
11
# File 'lib/cora.rb', line 9

def plugins
  @plugins ||= []
end

#process(text) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cora.rb', line 13

def process(text)
  log "Processing '#{text}'"

  if @callback
    log "Active callback found, resuming"

    # We must set the active callback to nil first, otherwise
    # multiple callbacks within one listen block won't work
    callback = @callback
    @callback = nil
    callback.call(text)
    return true
  end

  plugins.each do |plugin|
    log "Processing plugin #{plugin}"
    return true if plugin.process(text)
  end

  log "No matches for '#{text}'"
  no_matches
end

#respond(text, options = {}) ⇒ Object



36
37
# File 'lib/cora.rb', line 36

def respond(text, options = {})
end

#set_active_fiber(fiber) ⇒ Object



51
52
53
# File 'lib/cora.rb', line 51

def set_active_fiber(fiber)
  @fiber = fiber
end

#set_callback(&block) ⇒ Object



47
48
49
# File 'lib/cora.rb', line 47

def set_callback(&block)
  @callback = block
end

#set_location(latitude, longitude, extra = {}) ⇒ Object



55
56
57
# File 'lib/cora.rb', line 55

def set_location(latitude, longitude, extra = {})
  @location = Location.new(latitude, longitude, extra)
end

#set_priority_plugin(plugin) ⇒ Object



42
43
44
45
# File 'lib/cora.rb', line 42

def set_priority_plugin(plugin)
  plugins.delete(plugin)
  plugins.unshift(plugin)
end