Class: AdHocTemplate::RecordReader::ReaderState

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_hoc_template/record_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, stack = []) ⇒ ReaderState



85
86
87
88
89
# File 'lib/ad_hoc_template/record_reader.rb', line 85

def initialize(config={}, stack=[])
  @stack = stack
  @configs = [config]
  setup_reader
end

Instance Attribute Details

#current_block_labelObject

Returns the value of attribute current_block_label.



83
84
85
# File 'lib/ad_hoc_template/record_reader.rb', line 83

def current_block_label
  @current_block_label
end

Instance Method Details

#current_readerObject



103
104
105
# File 'lib/ad_hoc_template/record_reader.rb', line 103

def current_reader
  @stack[-1]
end

#current_recordObject



121
122
123
# File 'lib/ad_hoc_template/record_reader.rb', line 121

def current_record
  @configs[-1]
end

#last_block_valueObject



139
140
141
# File 'lib/ad_hoc_template/record_reader.rb', line 139

def last_block_value
  current_record[current_block_label]
end

#parsed_recordObject



125
126
127
# File 'lib/ad_hoc_template/record_reader.rb', line 125

def parsed_record
  @configs[0]
end

#popObject



95
96
97
# File 'lib/ad_hoc_template/record_reader.rb', line 95

def pop
  @stack.pop unless @stack.length == 1
end

#pop_current_recordObject



117
118
119
# File 'lib/ad_hoc_template/record_reader.rb', line 117

def pop_current_record
  @configs.pop
end

#push(reader) ⇒ Object



91
92
93
# File 'lib/ad_hoc_template/record_reader.rb', line 91

def push(reader)
  @stack.push reader
end

#push_new_recordObject



111
112
113
114
115
# File 'lib/ad_hoc_template/record_reader.rb', line 111

def push_new_record
  new_record = {}
  @configs.push new_record
  new_record
end

#read(line) ⇒ Object



107
108
109
# File 'lib/ad_hoc_template/record_reader.rb', line 107

def read(line)
  @stack[-1].read(line)
end

#read_record(lines) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/ad_hoc_template/record_reader.rb', line 129

def read_record(lines)
  lines = lines.each_line.to_a if lines.kind_of? String
  lines.each do |line|
    setup_stack(line)
    read(line)
  end
  remove_trailing_empty_lines_from_last_block!
  parsed_record
end

#remove_trailing_empty_lines_from_last_block!Object



143
144
145
146
147
# File 'lib/ad_hoc_template/record_reader.rb', line 143

def remove_trailing_empty_lines_from_last_block!
  if current_reader.kind_of? BlockReader
    last_block_value.sub!(/(#{$/})+\Z/, $/)
  end
end

#setup_stack(line) ⇒ Object



99
100
101
# File 'lib/ad_hoc_template/record_reader.rb', line 99

def setup_stack(line)
  @stack[-1].setup_stack(line)
end