Class: UncleKryon::Trainers
- Inherits:
-
Object
- Object
- UncleKryon::Trainers
- Defined in:
- lib/unclekryon/trainer.rb
Instance Attribute Summary collapse
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#trainers ⇒ Object
Returns the value of attribute trainers.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, trainer) ⇒ Object
-
#initialize(filepath = nil) ⇒ Trainers
constructor
A new instance of Trainers.
- #load_file ⇒ Object
- #save_to_file ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filepath = nil) ⇒ Trainers
Returns a new instance of Trainers.
117 118 119 120 |
# File 'lib/unclekryon/trainer.rb', line 117 def initialize(filepath=nil) @filepath = filepath @trainers = {} end |
Instance Attribute Details
#filepath ⇒ Object
Returns the value of attribute filepath.
114 115 116 |
# File 'lib/unclekryon/trainer.rb', line 114 def filepath @filepath end |
#trainers ⇒ Object
Returns the value of attribute trainers.
115 116 117 |
# File 'lib/unclekryon/trainer.rb', line 115 def trainers @trainers end |
Instance Method Details
#[](id) ⇒ Object
156 157 158 |
# File 'lib/unclekryon/trainer.rb', line 156 def [](id) @trainers[id] end |
#[]=(id, trainer) ⇒ Object
160 161 162 |
# File 'lib/unclekryon/trainer.rb', line 160 def []=(id,trainer) @trainers[id] = trainer end |
#load_file ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# 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]. = trainer..merge(@trainers[id].) @trainers[id].trainer = trainer.trainer end @trainers[id].trainer.reset_after_import @trainers[id].init_lengths end end end |
#save_to_file ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# 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 ⇒ Object
164 165 166 |
# File 'lib/unclekryon/trainer.rb', line 164 def to_s return YAML.dump(@trainers) end |