class CoinSync::Config
Constants
- DEFAULT_CONFIG
Attributes
settings[R]
source_definitions[R]
Public Class Methods
load_from_file(filename = nil)
click to toggle source
# File lib/coinsync/config.rb, line 16 def self.load_from_file(filename = nil) yaml = YAML.load(File.read(filename || DEFAULT_CONFIG)) self.new(yaml, filename) end
new(yaml, config_path = nil)
click to toggle source
# File lib/coinsync/config.rb, line 21 def initialize(yaml, config_path = nil) @source_definitions = yaml['sources'] or raise 'Config: No sources listed' @settings = yaml['settings'] || {} @labels = @settings['labels'] || {} if includes = yaml['include'] includes.each do |file| directory = config_path ? [config_path, '..'] : ['.'] require(File.expand_path(File.join(*directory, file))) end end end
Public Instance Methods
base_cryptocurrencies()
click to toggle source
# File lib/coinsync/config.rb, line 57 def base_cryptocurrencies settings['base_cryptocurrencies'] || ['USDT', 'BTC', 'ETH', 'BNB', 'KCS', 'LTC', 'BCH', 'NEO'] end
column_separator()
click to toggle source
# File lib/coinsync/config.rb, line 61 def column_separator settings['column_separator'] || ',' end
currency_conversion()
click to toggle source
# File lib/coinsync/config.rb, line 73 def currency_conversion settings['convert_currency'] && CurrencyConversionOptions.new(settings['convert_currency']) end
custom_decimal_separator()
click to toggle source
# File lib/coinsync/config.rb, line 69 def custom_decimal_separator settings['decimal_separator'] end
decimal_separator()
click to toggle source
# File lib/coinsync/config.rb, line 65 def decimal_separator custom_decimal_separator || '.' end
filtered_sources(selected, except = nil)
click to toggle source
# File lib/coinsync/config.rb, line 38 def filtered_sources(selected, except = nil) included = if selected.nil? || selected.empty? sources.values else selected = [selected] unless selected.is_a?(Array) selected.map do |key| sources[key] or raise "Source not found in the config file: '#{key}'" end end if except except = [except] unless except.is_a?(Array) included -= except.map { |key| sources[key] } end Hash[included.map { |source| [source.key, source] }] end
sources()
click to toggle source
# File lib/coinsync/config.rb, line 34 def sources @sources ||= Hash[@source_definitions.keys.map { |key| [key, Source.new(self, key)] }] end
time_format()
click to toggle source
# File lib/coinsync/config.rb, line 81 def time_format settings['time_format'] end
timezone()
click to toggle source
# File lib/coinsync/config.rb, line 85 def timezone settings['timezone'] && TZInfo::Timezone.get(settings['timezone']) end
translate(label)
click to toggle source
# File lib/coinsync/config.rb, line 89 def translate(label) @labels[label] || label end
value_estimation()
click to toggle source
# File lib/coinsync/config.rb, line 77 def value_estimation settings['estimate_value'] && ValueEstimationOptions.new(settings['estimate_value']) end