Class: FlattenDB::Base
- Inherits:
-
Object
- Object
- FlattenDB::Base
- Defined in:
- lib/flattendb/base.rb
Constant Summary collapse
- BUILDER_OPTIONS =
{ :xml => { :indent => 2 } }
- ELEMENT_START =
%r{^[a-zA-Z_:]}
- ELEMENT_CHARS =
%q{\w:.-}
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #flatten!(*args) ⇒ Object
-
#initialize(infiles, outfile, config) ⇒ Base
constructor
A new instance of Base.
- #to_xml(*args) ⇒ Object
Constructor Details
#initialize(infiles, outfile, config) ⇒ Base
Returns a new instance of Base.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/flattendb/base.rb', line 70 def initialize(infiles, outfile, config) config = case config when Hash config when String # assume file name YAML.load_file(config) else raise ArgumentError, "invalid config argument of type '#{config.class}'" end raise ArgumentError, "can't have more than one primary (root) table" if config.size > 1 (@root, @config), _ = *config # get "first" (and only) hash element @input = [*infiles].map { |infile| case infile when String infile when File infile.path else raise ArgumentError, "invalid infile argument of type '#{infile.class}'" end } @output = case outfile when IO outfile when String # assume file name File.open(outfile, 'w') else raise ArgumentError, "invalid outfile argument of type '#{outfile.class}'" end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
68 69 70 |
# File 'lib/flattendb/base.rb', line 68 def config @config end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
68 69 70 |
# File 'lib/flattendb/base.rb', line 68 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
68 69 70 |
# File 'lib/flattendb/base.rb', line 68 def output @output end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
68 69 70 |
# File 'lib/flattendb/base.rb', line 68 def root @root end |
Class Method Details
.[](type) ⇒ Object
56 57 58 |
# File 'lib/flattendb/base.rb', line 56 def [](type) types[type] end |
.types ⇒ Object
52 53 54 |
# File 'lib/flattendb/base.rb', line 52 def types Base.instance_variable_get :@types end |
Instance Method Details
#flatten!(*args) ⇒ Object
106 107 108 |
# File 'lib/flattendb/base.rb', line 106 def flatten!(*args) raise NotImplementedError, 'must be defined by sub-class' end |
#to_xml(*args) ⇒ Object
110 111 112 |
# File 'lib/flattendb/base.rb', line 110 def to_xml(*args) raise NotImplementedError, 'must be defined by sub-class' end |