class Source

Public Class Methods

new(conf_in) click to toggle source
# File lib/abelard/load.rb, line 229
def initialize(conf_in)
  if conf_in.respond_to?(:keys)
    @conf = conf_in
  else
    @conf = get_config(conf_in) || die("No config for #{conf_in}")
  end
end

Public Instance Methods

all_configs() click to toggle source
# File lib/abelard/load.rb, line 258
def all_configs
  YAML.load_file(CONFIG_FILE) || {}
end
get_config(key) click to toggle source
# File lib/abelard/load.rb, line 262
def get_config(key)
  configuration_file = all_configs
  configuration_file[key]
end
load() click to toggle source
# File lib/abelard/load.rb, line 237
def load
  conf = @conf
  dest = conf["dest"] || die("No 'dest' directory defined")
  urls = conf["urls"] || die("No urls defined")

  ensure_dest(dest)

  fetcher = Fetcher.new
  fetcher.user = conf["user"]
  fetcher.password = conf["password"]

  urls.each do |urlpath|
    url = URI(urlpath)
    fetcher.get(url) do |response|
      write_raw(response.body, "#{dest}/raw.xml") if Debug
      parser = LibXML::XML::Parser.string(response.body)
      process(parser, dest)
    end
  end
end
save_config(key, conf) click to toggle source
# File lib/abelard/load.rb, line 267
def save_config(key, conf)
  configuration_data = all_configs
  if configuration_data.has_key? key
    die("Already have config for #{key}")
  else
    configuration_data[key] = conf
    open(CONFIG_FILE, 'w+') do |conf_file|
      conf_file.puts(configuration_data.to_yaml)
    end
  end
end
write_raw(data, filename) click to toggle source
# File lib/abelard/load.rb, line 279
def write_raw(data, filename)
  File.open(filename, "w") { |f| f.write(data) }
end