Class: TSM::Command::Response

Inherits:
Hash
  • Object
show all
Defined in:
lib/tsm.rb

Instance Method Summary collapse

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

#validate(err = Error::FatalError) ⇒ Object



226
227
228
229
230
231
# File 'lib/tsm.rb', line 226

def validate(err=Error::FatalError)
	self[:messages].each do |msg|
		raise Error::SqlError::NoData, msg[:msg] if msg[:id] =~ /ANR2034E/i
		raise err, msg[:msg] if msg[:id][-1..-1] =~ /^[ES]$/i
	end
end