Sha256: d0f31840993fc3afae2b8fb041138f362fb1274d135a3b7b4abb1618caf97cd6

Contents?: true

Size: 543 Bytes

Versions: 2

Compression:

Stored size: 543 Bytes

Contents

#
# 把文本转化成对象的Build模式
#
#
class LineBuilder
	attr_accessor :data,:index,:object
	def initialize(data,index=0)
		@data = data
		@index = index
		@object = nil
	end
	def parse
		begin
			next unless in?
			process_line 
		end until ( out? )
		@object
	end
	# 行处理函数,必须被重写
	def process_line
		line = @data[@index]
		@object = line
	end
	# 进入条件,默认直接进入
	def in?
		true
	end
	# 退出条件,默认为读完本行直接退出,重写要设置@index的新值
	def out?
		@index += 1
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git-hack-0.0.2 lib/core_ext/line_builder.rb
git-hack-0.0.1 lib/core_ext/line_builder.rb