Class: TextBoxParser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/surveyor_gui/models/question_type_methods.rb

Instance Method Summary collapse

Methods included from Enumerable

#arraysum, #average, #dups, #sample_variance, #standard_deviation

Constructor Details

#initialize(args) ⇒ TextBoxParser

Returns a new instance of TextBoxParser.



427
428
429
430
431
# File 'lib/surveyor_gui/models/question_type_methods.rb', line 427

def initialize(args)
  @text = args[:textbox].to_s.gsub("\r","")
  @nested_objects = args[:records_to_update]
  @starting_display_order = args.fetch(:starting_display_order,0)
end

Instance Method Details

#each(&block) ⇒ Object



433
434
435
# File 'lib/surveyor_gui/models/question_type_methods.rb', line 433

def each(&block)
  _lines.readlines.each(&block)
end

#update_or_create_records(update_params = {}, &create_object) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/surveyor_gui/models/question_type_methods.rb', line 437

def update_or_create_records(update_params={}, &create_object)
  #takes a code block to customize creation of new objects
  #update and delete operations are always the same.  For now.
  _lines.readlines.each_with_index do |line, display_order|
    _update_or_create(
      line.strip,
      display_order + @starting_display_order,
      update_params,
      &create_object
    ) unless line.blank?
  end
  _delete_orphans
end