Class: LineBuilder
- Inherits:
-
Object
- Object
- LineBuilder
- Defined in:
- lib/core_ext/line_builder.rb
Overview
把文本转化成对象的Build模式
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#index ⇒ Object
Returns the value of attribute index.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
-
#in? ⇒ Boolean
进入条件,默认直接进入.
-
#initialize(data, index = 0) ⇒ LineBuilder
constructor
A new instance of LineBuilder.
-
#out? ⇒ Boolean
退出条件,默认为读完本行直接退出,重写要设置@index的新值.
- #parse ⇒ Object
-
#process_line ⇒ Object
行处理函数,必须被重写.
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
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/core_ext/line_builder.rb', line 6 def data @data end |
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/core_ext/line_builder.rb', line 6 def index @index end |
#object ⇒ Object
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
进入条件,默认直接进入
25 26 27 |
# File 'lib/core_ext/line_builder.rb', line 25 def in? true end |
#out? ⇒ Boolean
退出条件,默认为读完本行直接退出,重写要设置@index的新值
29 30 31 |
# File 'lib/core_ext/line_builder.rb', line 29 def out? @index += 1 end |
#parse ⇒ Object
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_line ⇒ Object
行处理函数,必须被重写
20 21 22 23 |
# File 'lib/core_ext/line_builder.rb', line 20 def process_line line = @data[@index] @object = line end |