Class: Aio::Module::InputStyle::Console::CmdContext
- Inherits:
-
Object
- Object
- Aio::Module::InputStyle::Console::CmdContext
- Defined in:
- lib/modules/input/style/console.rb
Instance Attribute Summary collapse
-
#all_info ⇒ Object
all_info = [[device_name, cmd, context] … ].
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#context ⇒ Object
Returns the value of attribute context.
-
#device_name ⇒ Object
Returns the value of attribute device_name.
Instance Method Summary collapse
- #clear ⇒ Object
- #done ⇒ Object
- #has_cmd? ⇒ Boolean
-
#initialize ⇒ CmdContext
constructor
A new instance of CmdContext.
Constructor Details
#initialize ⇒ CmdContext
Returns a new instance of CmdContext.
54 55 56 57 58 59 |
# File 'lib/modules/input/style/console.rb', line 54 def initialize @device_name = "" @cmd = "" @context = [] @all_info = [] end |
Instance Attribute Details
#all_info ⇒ Object
all_info = [[device_name, cmd, context] … ]
52 53 54 |
# File 'lib/modules/input/style/console.rb', line 52 def all_info @all_info end |
#cmd ⇒ Object
Returns the value of attribute cmd.
49 50 51 |
# File 'lib/modules/input/style/console.rb', line 49 def cmd @cmd end |
#context ⇒ Object
Returns the value of attribute context.
49 50 51 |
# File 'lib/modules/input/style/console.rb', line 49 def context @context end |
#device_name ⇒ Object
Returns the value of attribute device_name.
49 50 51 |
# File 'lib/modules/input/style/console.rb', line 49 def device_name @device_name end |
Instance Method Details
#clear ⇒ Object
86 87 88 89 90 |
# File 'lib/modules/input/style/console.rb', line 86 def clear @device_name = "" @cmd = "" @context = [] end |
#done ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/modules/input/style/console.rb', line 61 def done # 当之前有cmd内容的时候,比较两个的长度 # 长的保留 info_idx = has_cmd? if info_idx if @all_info[info_idx][2].size < context.size @all_info[info_idx][2] = context end else # 如果都没有,那么就直接添加 @all_info << [device_name, cmd, context] end self.clear end |
#has_cmd? ⇒ Boolean
77 78 79 80 81 82 83 84 |
# File 'lib/modules/input/style/console.rb', line 77 def has_cmd? @all_info.each_with_index do |info, idx| next unless info[0] == device_name return idx if info[1] == cmd end return nil end |