# File lib/flattendb/base.rb, line 61 def [](type) types[type] end
# File lib/flattendb/base.rb, line 75 def initialize(options) config = options.select { |k, _| k.is_a?(String) } if config.size > 1 raise ArgumentError, "can't have more than one primary (root) table" end @root, @config = config.first @input, @output = options.values_at(:input, :output) end
# File lib/flattendb/base.rb, line 53 def to_flat!(*args) new(*args).flatten!.to_xml end
# File lib/flattendb/base.rb, line 57 def types Base.instance_variable_get(:@types) end
# File lib/flattendb/base.rb, line 67 def inherited(klass) types[klass.name.split('::')[1..-1].join('/').downcase.to_sym] = klass end
# File lib/flattendb/base.rb, line 87 def flatten!(*args) raise NotImplementedError, 'must be defined by sub-class' end
# File lib/flattendb/base.rb, line 91 def to_xml(*args) raise NotImplementedError, 'must be defined by sub-class' end
# File lib/flattendb/base.rb, line 109 def column_to_element(column) element = column.dup element.insert(0, '_') unless element =~ ELEMENT_START element.gsub!(/[^#{ELEMENT_CHARS}]/, '') element end
# File lib/flattendb/base.rb, line 97 def initialize_builder(type, output, builder_options = {}) builder_options = (BUILDER_OPTIONS[type] || {}).merge(builder_options) @builder = case type when :xml Builder::XmlMarkup.new(builder_options.merge(:target => output)) else raise ArgumentError, "builder of type '#{type}' not supported" end end