module Athena

See README.

Constants

DEFAULT_EMPTY
DEFAULT_SEPARATOR
VERSION

Public Instance Methods

input_formats() click to toggle source
# File lib/athena.rb, line 52
def input_formats
  Formats.formats[:in].sort
end
output_formats() click to toggle source
# File lib/athena.rb, line 56
def output_formats
  Formats.formats[:out].sort
end
run(config, spec, format, input, output) click to toggle source
# File lib/athena.rb, line 45
def run(config, spec, format, input, output)
  Formats[:out, format, output].run(
    Formats[:in, spec, build_config(config)],
    input
  )
end
valid_format?(direction, format) click to toggle source
# File lib/athena.rb, line 60
def valid_format?(direction, format)
  Formats.valid_format?(direction, format)
end
valid_input_format?(format) click to toggle source
# File lib/athena.rb, line 64
def valid_input_format?(format)
  valid_format?(:in, format)
end
valid_output_format?(format) click to toggle source
# File lib/athena.rb, line 68
def valid_output_format?(format)
  valid_format?(:out, format)
end

Private Instance Methods

build_config(config) click to toggle source
# File lib/athena.rb, line 74
def build_config(config)
  hash = {}

  config.each { |field, value|
    if field.to_s =~ /\A__/
      hash[field] = value
    else
      case value
        when String, Array
          elements, value = [*value], {}
        when Hash
          elements = value[:elements] || value[:element].to_a

          raise ArgumentError, "no elements specified for field #{field}" unless elements.is_a?(Array)
        else
          raise ArgumentError, "illegal value for field #{field}"
      end

      separator = value[:separator] || DEFAULT_SEPARATOR

      elements.each { |element|
        (hash[element] ||= {})[field] = {
          :string   => value[:string] || ['%s'] * elements.size * separator,
          :empty    => value[:empty]  || DEFAULT_EMPTY,
          :elements => elements
        }
      }
    end
  }

  hash
end