Sha256: 37a9e0f8e4890e63d7c3d7384e634a2dad7c75a62ad3dc1195d8b3aa39bbc306

Contents?: true

Size: 866 Bytes

Versions: 5

Compression:

Stored size: 866 Bytes

Contents

module Maths
	class Brain
    
    # Public: Assigns data
    def self.assign(variable, value)
      data = read
      data[variable] = value
      write(data)
      
      value
    end
    
    # Public: Looks up data
    def self.lookup(variable)
      value = read[variable]
      
      if value.nil?
        nil
      else
        BigDecimal.new(read[variable])
      end
    end
    
    # Public: The file we're using to store our memories
    def self.brain_file
      File.join(ENV['HOME'], ".maths_brain")
    end
    
    # Public: Reads the data out of the brain
    def self.read
      if File.exist?(brain_file)
        JSON.parse(File.read(brain_file))
      else
        {}
      end
    end
    
    # Public: Reads the 
    def self.write(data)
      File.open(brain_file, "wb") do |file|
        file << JSON.dump(data)
      end
    end
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maths-0.0.7 lib/maths/brain.rb
maths-0.0.6 lib/maths/brain.rb
maths-0.0.5 lib/maths/brain.rb
maths-0.0.4 lib/maths/brain.rb
maths-0.0.3 lib/maths/brain.rb