Class: Geppeto::Scout

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, id = nil) ⇒ Scout

Returns a new instance of Scout.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scout.rb', line 18

def initialize(connection, id = nil)
  @id = id
  @conn = connection
  @options = Array.new
  @logger = @conn.logger ? @conn.logger : Logger.new(STDOUT)

  @events = Geppeto::Commands::Events.new(self)
  @hq  = Geppeto::Commands::Hq.new(self)
  @led = Geppeto::Commands::Led.new(self)
  @memory = Geppeto::Commands::Memory.new(self)
  @mesh = Geppeto::Commands::Mesh.new(self)
  @pin = Geppeto::Commands::Pin.new(self)
  @power = Geppeto::Commands::Power.new(self)
  @uptime = Geppeto::Commands::Uptime.new(self)
  @wifi = Geppeto::Commands::Wifi.new(self)
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



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

def events
  @events
end

#hqObject (readonly)

Returns the value of attribute hq.



8
9
10
# File 'lib/scout.rb', line 8

def hq
  @hq
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/scout.rb', line 3

def id
  @id
end

#last_reportObject

Returns the value of attribute last_report.



4
5
6
# File 'lib/scout.rb', line 4

def last_report
  @last_report
end

#ledObject (readonly)

Returns the value of attribute led.



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

def led
  @led
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/scout.rb', line 5

def logger
  @logger
end

#memoryObject (readonly)

Returns the value of attribute memory.



10
11
12
# File 'lib/scout.rb', line 10

def memory
  @memory
end

#meshObject (readonly)

Returns the value of attribute mesh.



11
12
13
# File 'lib/scout.rb', line 11

def mesh
  @mesh
end

#pinObject (readonly)

Returns the value of attribute pin.



12
13
14
# File 'lib/scout.rb', line 12

def pin
  @pin
end

#powerObject (readonly)

Returns the value of attribute power.



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

def power
  @power
end

#temperatureObject (readonly)

Returns the value of attribute temperature.



14
15
16
# File 'lib/scout.rb', line 14

def temperature
  @temperature
end

#uptimeObject (readonly)

Returns the value of attribute uptime.



15
16
17
# File 'lib/scout.rb', line 15

def uptime
  @uptime
end

#wifiObject (readonly)

Returns the value of attribute wifi.



16
17
18
# File 'lib/scout.rb', line 16

def wifi
  @wifi
end

Instance Method Details

#allObject



35
36
37
38
# File 'lib/scout.rb', line 35

def all
  @options << :all
  self
end

#bootObject



65
66
67
# File 'lib/scout.rb', line 65

def boot
  request("scout.boot")
end

#delay(ms = nil) ⇒ Object



59
60
61
62
63
# File 'lib/scout.rb', line 59

def delay(ms = nil)
  @options << :delay
  @_ms = ms
  self
end

#lead?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/scout.rb', line 49

def lead?
  request("print scout.isleadscout").to_i == 1
end

#othersObject



40
41
42
43
# File 'lib/scout.rb', line 40

def others
  @options << :others
  self
end

#randomnumberObject



53
54
55
# File 'lib/scout.rb', line 53

def randomnumber
  request("randomnumber")
end

#reportObject



45
46
47
# File 'lib/scout.rb', line 45

def report
  request("scout.report")
end

#request(command, *args, ms: nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/scout.rb', line 69

def request(command, *args, ms: nil)
  args_string = join_args(args)
  command, args_string = process_options(command, args_string)

  if args_string.empty?
    unless @id.nil?
      command = "command.scout(#{@id}, \"#{command}\")"
    else
      command = "#{command}()"
    end
  else
    unless @id.nil?
      command = "command.scout(#{@id}, \"#{command}\", #{args_string})"
    else
      command = "#{command}(#{args_string})"
    end
  end

  @logger.debug("Issuing: #{command}")
  @conn.write(command, ms)
end