Sha256: f9396f48be8ed0a3e95f17b355c9f54e01175e69dbafa7b1dbdb8ca0c0e3fd90

Contents?: true

Size: 870 Bytes

Versions: 7

Compression:

Stored size: 870 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.generate(data)
      end
    end
	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
maths-0.0.14 lib/maths/brain.rb
maths-0.0.13 lib/maths/brain.rb
maths-0.0.12 lib/maths/brain.rb
maths-0.0.11 lib/maths/brain.rb
maths-0.0.10 lib/maths/brain.rb
maths-0.0.9 lib/maths/brain.rb
maths-0.0.8 lib/maths/brain.rb