Class: LineBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/line_builder.rb

Overview

把文本转化成对象的Build模式

Direct Known Subclasses

GitHack::CommitLineBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, index = 0) ⇒ LineBuilder

Returns a new instance of LineBuilder.



7
8
9
10
11
# File 'lib/core_ext/line_builder.rb', line 7

def initialize(data,index=0)
	@data = data
	@index = index
	@object = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/core_ext/line_builder.rb', line 6

def data
  @data
end

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/core_ext/line_builder.rb', line 6

def index
  @index
end

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/core_ext/line_builder.rb', line 6

def object
  @object
end

Instance Method Details

#in?Boolean

进入条件,默认直接进入

Returns:

  • (Boolean)


25
26
27
# File 'lib/core_ext/line_builder.rb', line 25

def in?
	true
end

#out?Boolean

退出条件,默认为读完本行直接退出,重写要设置@index的新值

Returns:

  • (Boolean)


29
30
31
# File 'lib/core_ext/line_builder.rb', line 29

def out?
	@index += 1
end

#parseObject



12
13
14
15
16
17
18
# File 'lib/core_ext/line_builder.rb', line 12

def parse
	begin
		next unless in?
		process_line 
	end until ( out? )
	@object
end

#process_lineObject

行处理函数,必须被重写



20
21
22
23
# File 'lib/core_ext/line_builder.rb', line 20

def process_line
	line = @data[@index]
	@object = line
end