class Oolite::MarketFile

Public Class Methods

new() click to toggle source
# File lib/oolite/market_file.rb, line 15
def initialize
  Oolite.configure do |config|
    @save_file_path = Pathname(config.save_file_path)
    path = @save_file_path.dirname
    @market_data_path = path + (Pathname(config.market_data_filename).to_s + '.yml')
  end
end

Public Instance Methods

data() click to toggle source
# File lib/oolite/market_file.rb, line 23
def data
  @data ||= self.load
end
data=(new_data) click to toggle source
# File lib/oolite/market_file.rb, line 27
def data= new_data
  @data = new_data
end
load() click to toggle source
# File lib/oolite/market_file.rb, line 35
def load
  if @market_data_path.nil? || @market_data_path.to_s.empty? || !@market_data_path.exist?
    Hash.new
  else
    input = YAML.load_file(@market_data_path)
    input or Hash.new
  end
rescue
  Hash.new
end
systems() click to toggle source
# File lib/oolite/market_file.rb, line 31
def systems
  data.keys
end
write() click to toggle source
# File lib/oolite/market_file.rb, line 46
def write
  raise "Missing filename" if @market_data_path.nil? || @market_data_path.to_s.empty?

  File.open(@market_data_path, 'w') do |f|
    f.write data.to_yaml
  end
end