Class: FlattenDB::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/flattendb/base.rb

Direct Known Subclasses

MDB, MySQL

Constant Summary collapse

BUILDER_OPTIONS =
{
  :xml => {
    :indent => 2
  }
}
ELEMENT_START =
%r{^[a-zA-Z_:]}
ELEMENT_CHARS =
%q{\w:.-}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



75
76
77
78
79
80
81
82
83
84
85
# 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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



73
74
75
# File 'lib/flattendb/base.rb', line 73

def config
  @config
end

#inputObject (readonly)

Returns the value of attribute input.



73
74
75
# File 'lib/flattendb/base.rb', line 73

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



73
74
75
# File 'lib/flattendb/base.rb', line 73

def output
  @output
end

#rootObject (readonly)

Returns the value of attribute root.



73
74
75
# File 'lib/flattendb/base.rb', line 73

def root
  @root
end

Class Method Details

.[](type) ⇒ Object



61
62
63
# File 'lib/flattendb/base.rb', line 61

def [](type)
  types[type]
end

.to_flat!(*args) ⇒ Object



53
54
55
# File 'lib/flattendb/base.rb', line 53

def to_flat!(*args)
  new(*args).flatten!.to_xml
end

.typesObject



57
58
59
# File 'lib/flattendb/base.rb', line 57

def types
  Base.instance_variable_get(:@types)
end

Instance Method Details

#flatten!(*args) ⇒ Object

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/flattendb/base.rb', line 87

def flatten!(*args)
  raise NotImplementedError, 'must be defined by sub-class'
end

#to_xml(*args) ⇒ Object

Raises:

  • (NotImplementedError)


91
92
93
# File 'lib/flattendb/base.rb', line 91

def to_xml(*args)
  raise NotImplementedError, 'must be defined by sub-class'
end