Class: NabaztagHackKit::Bunny
- Inherits:
-
Object
- Object
- NabaztagHackKit::Bunny
- Defined in:
- lib/nabaztag_hack_kit/bunny.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_seen ⇒ Object
readonly
Returns the value of attribute last_seen.
-
#queued_commands ⇒ Object
readonly
Returns the value of attribute queued_commands.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id) ⇒ Bunny
constructor
A new instance of Bunny.
- #next_message! ⇒ Object
- #queue_commands(commands) ⇒ Object
- #seen! ⇒ Object
- #to_json(_state = nil, _deepth = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 9 def id @id end |
#last_seen ⇒ Object (readonly)
Returns the value of attribute last_seen.
9 10 11 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 9 def last_seen @last_seen end |
#queued_commands ⇒ Object (readonly)
Returns the value of attribute queued_commands.
9 10 11 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 9 def queued_commands @queued_commands end |
Class Method Details
.add(bunny) ⇒ Object
24 25 26 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 24 def add(bunny) @bunnies[bunny.id] = bunny end |
.all ⇒ Object
12 13 14 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 12 def all @bunnies.values end |
.find(id) ⇒ Object
16 17 18 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 16 def find(id) @bunnies[id] end |
Instance Method Details
#next_message! ⇒ Object
44 45 46 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 44 def Message.build(*@queued_commands.shift || Message::Api::OK) end |
#queue_commands(commands) ⇒ Object
40 41 42 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 40 def queue_commands(commands) @queued_commands << commands end |
#seen! ⇒ Object
36 37 38 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 36 def seen! @last_seen = Time.now end |
#to_json(_state = nil, _deepth = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/nabaztag_hack_kit/bunny.rb', line 48 def to_json(_state = nil, _deepth = nil) { id: id, last_seen: last_seen, queued_commands_size: queued_commands.size }.to_json end |