Class: Rdv::Object::Block

Inherits:
Base
  • Object
show all
Defined in:
lib/rdv/object/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#listObject

Returns the value of attribute list.



4
5
6
# File 'lib/rdv/object/block.rb', line 4

def list
  @list
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/rdv/object/block.rb', line 4

def name
  @name
end

#raw_listObject

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

#buildObject



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