Class: TSM::Command::Response
- Inherits:
-
Hash
- Object
- Hash
- TSM::Command::Response
- Defined in:
- lib/tsm.rb
Instance Method Summary collapse
-
#initialize(str = nil) ⇒ Response
constructor
A new instance of Response.
- #parse(chrs, &block) ⇒ Object
- #validate(err = Error::FatalError) ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ Response
Returns a new instance of Response.
185 186 187 188 189 190 191 192 193 |
# File 'lib/tsm.rb', line 185 def initialize(str=nil) {:messages => [],:rows => [],:count => 0,:command => nil}.each do |k,v| self.store(k,v) end self.parse(str) if str self end |
Instance Method Details
#parse(chrs, &block) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/tsm.rb', line 195 def parse(chrs,&block) chrs.each { |line| line = line.chomp line.strip! if (m = /(([ABDEI][DEKNC][ERSDNOUIP])(\d+)([IESWK])) (.*)/.match(line)) self[:messages].push({:id=>m[1],:msg=>m[5]}) and next end self[:command] = line and next unless self[:command] if line.empty? and not @tmp.empty? self[:count] += 1 yield @tmp if block_given? self[:rows].to_a.push(@tmp.dup) @tmp.clear next end if @tmp if (sp = line.index(":")) != nil @tmp = {} unless @tmp @tmp[line[0...sp].downcase.tr(" ","_").to_sym] = line[(sp+1)..-1].lstrip end } chrs end |