Class: Germinate::Reader

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
AlterEgo
Defined in:
lib/germinate/reader.rb

Overview

The Reader is responsible for reading a source file, breaking it down into into its constituent chunks of text, code, etc., assigning names to them, and filing them away in a Librarian. It is also responsible for interpreting any special control lines found in the input document.

Constant Summary collapse

CONTROL_PATTERN =
/^\s*([^\s\\]+)?\s*:([A-Z0-9_]+):\s*(.*)?\s*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(librarian) ⇒ Reader

Returns a new instance of Reader.



60
61
62
63
64
65
# File 'lib/germinate/reader.rb', line 60

def initialize(librarian)
  @librarian       = librarian
  @section_count   = 0
  @current_section = "SECTION0"
  @line_number     = 1
end

Instance Attribute Details

#current_sectionObject

Returns the value of attribute current_section.



16
17
18
# File 'lib/germinate/reader.rb', line 16

def current_section
  @current_section
end

#librarianObject (readonly)

Returns the value of attribute librarian.



15
16
17
# File 'lib/germinate/reader.rb', line 15

def librarian
  @librarian
end

#section_countObject

Returns the value of attribute section_count.



17
18
19
# File 'lib/germinate/reader.rb', line 17

def section_count
  @section_count
end

Instance Method Details

#<<(line) ⇒ Object

Read a line



68
69
70
71
72
73
# File 'lib/germinate/reader.rb', line 68

def <<(line)
  @line_number += 1
  unless handle_control_line!(line)
    add_line!(unescape(line))
  end
end

#increment_section_count!Object



75
76
77
78
# File 'lib/germinate/reader.rb', line 75

def increment_section_count!
  self.section_count = section_count.succ
  self.current_section = automatic_section_name
end