Class: Rdv::Object::Block
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_list ⇒ Object
Returns the value of attribute raw_list.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #build ⇒ Object
-
#initialize(header) ⇒ Block
constructor
A new instance of Block.
Methods inherited from Base
#capitalize, #clean, #trim_indentation
Constructor Details
#initialize(header) ⇒ Block
Returns a new instance of Block.
6 7 8 9 |
# File 'lib/rdv/object/block.rb', line 6 def initialize header @name = capitalize(header) @raw_list = [] end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
4 5 6 |
# File 'lib/rdv/object/block.rb', line 4 def list @list end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/rdv/object/block.rb', line 4 def name @name end |
#raw_list ⇒ Object
Returns the value of attribute raw_list.
4 5 6 |
# File 'lib/rdv/object/block.rb', line 4 def raw_list @raw_list end |
Instance Method Details
#add_line(line) ⇒ Object
11 12 13 |
# File 'lib/rdv/object/block.rb', line 11 def add_line(line) @raw_list << line end |
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rdv/object/block.rb', line 15 def build @list = @raw_list.reduce([]) do |list, line| line = trim_indentation(line) if line.match(/^[^\s]+/) list << Item.new(line) elsif list.length > 0 && line.length > 0 list.last.add_line(line) end list end @list.each(&:build) @name = clean(@name) end |