Class: CoinSync::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/coinsync/config.rb
Defined Under Namespace
Classes: CurrencyConversionOptions, ValueEstimationOptions
Constant Summary
collapse
- DEFAULT_CONFIG =
'config.yml'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(yaml, config_path = nil) ⇒ Config
Returns a new instance of Config.
21
22
23
24
25
26
27
28
29
30
31
32
|
# 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
|
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
12
13
14
|
# File 'lib/coinsync/config.rb', line 12
def settings
@settings
end
|
#source_definitions ⇒ Object
Returns the value of attribute source_definitions.
12
13
14
|
# File 'lib/coinsync/config.rb', line 12
def source_definitions
@source_definitions
end
|
Class Method Details
.load_from_file(filename = nil) ⇒ Object
16
17
18
19
|
# 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
|
Instance Method Details
#base_cryptocurrencies ⇒ Object
57
58
59
|
# File 'lib/coinsync/config.rb', line 57
def base_cryptocurrencies
settings['base_cryptocurrencies'] || ['USDT', 'BTC', 'ETH', 'BNB', 'KCS', 'LTC', 'BCH', 'NEO']
end
|
#column_separator ⇒ Object
61
62
63
|
# File 'lib/coinsync/config.rb', line 61
def column_separator
settings['column_separator'] || ','
end
|
#currency_conversion ⇒ Object
73
74
75
|
# File 'lib/coinsync/config.rb', line 73
def currency_conversion
settings['convert_currency'] && CurrencyConversionOptions.new(settings['convert_currency'])
end
|
#custom_decimal_separator ⇒ Object
69
70
71
|
# File 'lib/coinsync/config.rb', line 69
def custom_decimal_separator
settings['decimal_separator']
end
|
#decimal_separator ⇒ Object
65
66
67
|
# File 'lib/coinsync/config.rb', line 65
def decimal_separator
custom_decimal_separator || '.'
end
|
#filtered_sources(selected, except = nil) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# 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 ⇒ Object
34
35
36
|
# File 'lib/coinsync/config.rb', line 34
def sources
@sources ||= Hash[@source_definitions.keys.map { |key| [key, Source.new(self, key)] }]
end
|
81
82
83
|
# File 'lib/coinsync/config.rb', line 81
def time_format
settings['time_format']
end
|
#timezone ⇒ Object
85
86
87
|
# File 'lib/coinsync/config.rb', line 85
def timezone
settings['timezone'] && TZInfo::Timezone.get(settings['timezone'])
end
|
#translate(label) ⇒ Object
89
90
91
|
# File 'lib/coinsync/config.rb', line 89
def translate(label)
@labels[label] || label
end
|
#value_estimation ⇒ Object
77
78
79
|
# File 'lib/coinsync/config.rb', line 77
def value_estimation
settings['estimate_value'] && ValueEstimationOptions.new(settings['estimate_value'])
end
|