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, source_path = nil) ⇒ Reader

Returns a new instance of Reader.



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

def initialize(librarian, source_path=nil)
  @librarian       = librarian
  @section_count   = 0
  @current_section = "SECTION0"
  @line_number     = 0
  @source_path     = source_path ? Pathname(source_path) : nil
  librarian.source_path = @source_path
end

Instance Attribute Details

#current_sectionObject

Returns the value of attribute current_section.



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

def current_section
  @current_section
end

#librarianObject (readonly)

Returns the value of attribute librarian.



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

def librarian
  @librarian
end

#section_countObject

Returns the value of attribute section_count.



19
20
21
# File 'lib/germinate/reader.rb', line 19

def section_count
  @section_count
end

Instance Method Details

#<<(line) ⇒ Object

Read a line



78
79
80
81
82
83
# File 'lib/germinate/reader.rb', line 78

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

#increment_section_count!Object



85
86
87
88
# File 'lib/germinate/reader.rb', line 85

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