Class: Andromeda::Cmd::Cmd
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #comment ⇒ Object
- #comment=(str = nil) ⇒ Object
- #if_cmd(sym) ⇒ Object
-
#initialize(cmd, data = {}, cmd_time = nil) ⇒ Cmd
constructor
A new instance of Cmd.
- #to_s ⇒ Object
- #with_comment(str = nil) ⇒ Object
Constructor Details
#initialize(cmd, data = {}, cmd_time = nil) ⇒ Cmd
Returns a new instance of Cmd.
10 11 12 13 14 15 16 |
# File 'lib/andromeda/cmd.rb', line 10 def initialize(cmd, data = {}, cmd_time = nil) raise ArgumentError unless cmd.kind_of?(Symbol) @cmd = cmd @data = data @time = if cmd_time then cmd_time else Time.now.to_i end @comment = nil end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/andromeda/cmd.rb', line 6 def cmd @cmd end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/andromeda/cmd.rb', line 7 def data @data end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
8 9 10 |
# File 'lib/andromeda/cmd.rb', line 8 def time @time end |
Class Method Details
Instance Method Details
#as_json ⇒ Object
23 24 25 26 27 28 |
# File 'lib/andromeda/cmd.rb', line 23 def as_json h = { cmd: cmd, data: (data.as_json rescue data), time: time } c = @comment h[:comment] = c if c h end |
#comment ⇒ Object
18 |
# File 'lib/andromeda/cmd.rb', line 18 def comment ; @comment || '' end |
#comment=(str = nil) ⇒ Object
19 |
# File 'lib/andromeda/cmd.rb', line 19 def comment=(str = nil) ; @comment = str end |
#if_cmd(sym) ⇒ Object
21 |
# File 'lib/andromeda/cmd.rb', line 21 def if_cmd(sym) ; if sym == cmd then yield data else seld end end |
#to_s ⇒ Object
30 |
# File 'lib/andromeda/cmd.rb', line 30 def to_s ; as_json.to_json end |
#with_comment(str = nil) ⇒ Object
32 33 34 35 |
# File 'lib/andromeda/cmd.rb', line 32 def with_comment(str = nil) @comment = str self end |