class UncleKryon::Trainers

Attributes

filepath[RW]
trainers[RW]

Public Class Methods

new(filepath=nil) click to toggle source
# File lib/unclekryon/trainer.rb, line 117
def initialize(filepath=nil)
  @filepath = filepath
  @trainers = {}
end

Public Instance Methods

[](id) click to toggle source
# File lib/unclekryon/trainer.rb, line 156
def [](id)
  @trainers[id]
end
[]=(id,trainer) click to toggle source
# File lib/unclekryon/trainer.rb, line 160
def []=(id,trainer)
  @trainers[id] = trainer
end
load_file() click to toggle source
# File lib/unclekryon/trainer.rb, line 122
def load_file
  if @filepath.nil? || (@filepath = @filepath.strip).empty?
    raise ArgumentError,'Training filepath cannot be empty'
  end

  if File.exist?(@filepath)
    y = YAML.load_file(@filepath)

    y.each do |id,trainer|
      if !@trainers.key?(id)
        @trainers[id] = trainer
      else
        @trainers[id].tags = trainer.tags.merge(@trainers[id].tags)
        @trainers[id].trainer = trainer.trainer
      end

      @trainers[id].trainer.reset_after_import
      @trainers[id].init_lengths
    end
  end
end
save_to_file() click to toggle source
# File lib/unclekryon/trainer.rb, line 144
def save_to_file
  if @filepath.nil? || (@filepath = @filepath.strip).empty?
    raise ArgumentError,'Training filepath cannot be empty'
  end

  Util.mk_dirs_from_filepath(@filepath)

  File.open(@filepath,'w') do |f|
    f.write(to_s)
  end
end
to_s() click to toggle source
# File lib/unclekryon/trainer.rb, line 164
def to_s
  return YAML.dump(@trainers)
end