Class: CoinSync::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/coinsync/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, key) ⇒ Source

Returns a new instance of Source.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/coinsync/source.rb', line 7

def initialize(config, key)
  @config = config
  @key = key

  definition = config.source_definitions[key]

  if definition.is_a?(Hash)
    @params = definition
    @filename = definition['file']
    type = (definition['type'] || key).to_sym
  elsif definition.is_a?(String)
    @params = {}
    @filename = definition
    type = key.to_sym
  elsif !config.source_definitions.has_key?(key)
    raise "No such key in source list: '#{key}'"
  else
    raise "Unexpected source definition for '#{key}': #{definition}"
  end

  @importer_class = Importers.registered[type]

  if @importer_class.nil?
    if @params['type']
      raise "Unknown source type for '#{key}': #{params['type']}"
    else
      raise "Unknown source type for '#{key}': please include a 'type' parameter " +
        "or use a name of an existing importer"
    end
  end
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/coinsync/source.rb', line 5

def filename
  @filename
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/coinsync/source.rb', line 5

def key
  @key
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/coinsync/source.rb', line 5

def params
  @params
end

Instance Method Details

#importerObject



39
40
41
# File 'lib/coinsync/source.rb', line 39

def importer
  @importer ||= @importer_class.new(@config, @params)
end