lib/megahal/megahal.rb
# Load a brain that has previously been saved.
#
# @param [String] filename The brain file to be loaded.
# @param [ProgressBar] bar An optional progress bar instance.
Load a brain that has previously been saved.
Load a brain that has previously been saved .
def load(filename, bar = nil)
    bar.total = 6 unless bar.nil?
    Zip::File.open(filename) do |zipfile|
      data = Marshal::load(zipfile.find_entry("dictionary").get_input_stream.read)
      raise "bad version" unless data[:version] == "MH11"
      @learning = data[:learning]
      @brain = data[:brain]
      @dictionary = data[:dictionary]
      bar.increment unless bar.nil?
      [:seed, :fore, :back, :case, :punc].each do |name|
        tmp = _get_tmp_filename(name)
        zipfile.find_entry(name.to_s).extract(tmp)      
        instance_variable_get("@#{name}").load(tmp)
        bar.increment unless bar.nil?
      end
    end
  end
def load ( filename , bar = nil ) bar . total = 6 unless bar . nil? Zip :: File . open ( filename ) do | zipfile | data = Marshal :: load ( zipfile . find_entry ( "dictionary" ) . get_input_stream . read ) raise "bad version" unless data [ :version ] == "MH11" @learning = data [ :learning ] @brain = data [ :brain ] @dictionary = data [ :dictionary ] bar . increment unless bar . nil? [ :seed , :fore , :back , :case , :punc ] . each do | name | tmp = _get_tmp_filename ( name ) zipfile . find_entry ( name . to_s ) . extract ( tmp ) instance_variable_get ( "@#{name}" ) . load ( tmp ) bar . increment unless bar . nil? end end end
Load a brain that has previously been saved.
Load a brain that has previously been saved .
filename
bar
bar An optional progress bar instance.
bar An optional progress bar instance .