Class: Aio::Module::InputStyle::Console::CmdContext

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/input/style/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCmdContext

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_infoObject

all_info = [[device_name, cmd, context] … ]



52
53
54
# File 'lib/modules/input/style/console.rb', line 52

def all_info
  @all_info
end

#cmdObject

Returns the value of attribute cmd.



49
50
51
# File 'lib/modules/input/style/console.rb', line 49

def cmd
  @cmd
end

#contextObject

Returns the value of attribute context.



49
50
51
# File 'lib/modules/input/style/console.rb', line 49

def context
  @context
end

#device_nameObject

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

#clearObject



86
87
88
89
90
# File 'lib/modules/input/style/console.rb', line 86

def clear
  @device_name = ""
  @cmd = ""
  @context = []
end

#doneObject



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

Returns:

  • (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