Class: AdHocTemplate::RecordReader::DefaultFormReader::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

Returns a new instance of ReaderState.



196
197
198
199
200
# File 'lib/ad_hoc_template/record_reader.rb', line 196

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.



194
195
196
# File 'lib/ad_hoc_template/record_reader.rb', line 194

def current_block_label
  @current_block_label
end

Instance Method Details

#current_readerObject



214
215
216
# File 'lib/ad_hoc_template/record_reader.rb', line 214

def current_reader
  @stack[-1]
end

#current_recordObject



232
233
234
# File 'lib/ad_hoc_template/record_reader.rb', line 232

def current_record
  @configs[-1]
end

#last_block_valueObject



250
251
252
# File 'lib/ad_hoc_template/record_reader.rb', line 250

def last_block_value
  current_record[current_block_label]
end

#parsed_recordObject



236
237
238
# File 'lib/ad_hoc_template/record_reader.rb', line 236

def parsed_record
  @configs[0]
end

#popObject



206
207
208
# File 'lib/ad_hoc_template/record_reader.rb', line 206

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

#pop_current_recordObject



228
229
230
# File 'lib/ad_hoc_template/record_reader.rb', line 228

def pop_current_record
  @configs.pop
end

#push(reader) ⇒ Object



202
203
204
# File 'lib/ad_hoc_template/record_reader.rb', line 202

def push(reader)
  @stack.push reader
end

#push_new_recordObject



222
223
224
225
226
# File 'lib/ad_hoc_template/record_reader.rb', line 222

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

#read(line) ⇒ Object



218
219
220
# File 'lib/ad_hoc_template/record_reader.rb', line 218

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

#read_record(lines) ⇒ Object



240
241
242
243
244
245
246
247
248
# File 'lib/ad_hoc_template/record_reader.rb', line 240

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



254
255
256
257
258
# File 'lib/ad_hoc_template/record_reader.rb', line 254

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



210
211
212
# File 'lib/ad_hoc_template/record_reader.rb', line 210

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