Sha256: dffaef8fc5a14ad6315b5d534aa4b95fedbe604e3bc5a240c31916d5651c191b
Contents?: true
Size: 1.99 KB
Versions: 2
Compression:
Stored size: 1.99 KB
Contents
# frozen_string_literal: true module Cotcube module Bardata def symbols(config: init) if config[:symbols_file].nil? SYMBOL_EXAMPLES else CSV .read(config[:symbols_file], headers: %i{ id symbol ticksize power months type bcf reports name}) .map{|row| row.to_h } .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row } .reject{|row| row[:id].nil? } end end def config_prefix os = Gem::Platform.local.os case os when 'linux' '' when 'freebsd' '/usr/local' else raise RuntimeError, 'unknown architecture' end end def config_path config_prefix + '/etc/cotcube' end def init(config_file_name: 'bardata.yml', debug: false) name = 'bardata' config_file = config_path + "/#{config_file_name}" if File.exist?(config_file) config = YAML.load(File.read config_file).transform_keys(&:to_sym) else config = {} end defaults = { data_path: config_prefix + '/var/cotcube/' + name, } config = defaults.merge(config) # part 2 of init process: Prepare directories save_create_directory = lambda do |directory_name| unless Dir.exist?(directory_name) begin `mkdir -p #{directory_name}` unless $?.exitstatus.zero? puts "Missing permissions to create or access '#{directory_name}', please clarify manually" exit 1 unless defined?(IRB) end rescue puts "Missing permissions to create or access '#{directory_name}', please clarify manually" exit 1 unless defined?(IRB) end end end ['',:daily,:quarters].each do |path| dir = "#{config[:data_path]}#{path == '' ? '' : '/'}#{path.to_s}" save_create_directory.call(dir) end # eventually return config config end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cotcube-bardata-0.1.2 | lib/cotcube-bardata/init.rb |
cotcube-bardata-0.1.1 | lib/cotcube-bardata/init.rb |