module UkParliament

Module defining classes and methods enabling scraping of UK Parliament members contact data from parliament.uk web site, or loading of scraped data from file.

Constants

DATA_SOURCE_FILE

Constants representing where data can come from.

DATA_SOURCE_HTTP
VERSION

Public Class Methods

configuration() click to toggle source

Define set of configuration values for the module.

# File lib/uk_parliament.rb, line 45
def self.configuration
  if @configuration.nil?
    base_dir = File.join(Dir.home, 'uk_parliament')
    FileUtils.mkdir_p(base_dir) unless Dir.exist?(base_dir)

    @configuration = {
      :log_file_path => base_dir,
      :data_file_path => base_dir,
      :queue_file_path => base_dir,
      :scrape_no_of_threads => 4,
      :scrape_request_delay => 2,
      :backup_before_write => true
    }
  end

  @configuration
end
log() click to toggle source

Setup a Logger instance, if one doesn't already exist.

# File lib/uk_parliament.rb, line 29
def self.log
  if @log.nil?
    config = configuration
    @log = Logger.new(File.join(config[:log_file_path], 'uk_parliament.log'), 'daily')
    @log.level = Logger::INFO
  end

  @log
end

Public Instance Methods

configuration() click to toggle source

Setup module-wide access to a set of configuration values.

# File lib/uk_parliament.rb, line 40
def configuration
  UkParliament.configuration
end
log() click to toggle source

Setup module-wide access to Log to file.

# File lib/uk_parliament.rb, line 24
def log
  UkParliament.log
end