athena 0.0.1.53

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of athena, the database file converter. #
5
+ # #
6
+ # Copyright (C) 2007 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # athena is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU General Public License as published by the Free Software #
15
+ # Foundation; either version 3 of the License, or (at your option) any later #
16
+ # version. #
17
+ # #
18
+ # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
21
+ # details. #
22
+ # #
23
+ # You should have received a copy of the GNU General Public License along #
24
+ # with athena. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ module Athena
30
+
31
+ class Parser
32
+
33
+ include Util
34
+
35
+ attr_reader :config, :spec
36
+ attr_accessor :block
37
+
38
+ def initialize(config, spec)
39
+ @config = build_config(config)
40
+ @spec = Athena::Formats[:in, spec].new(self)
41
+ end
42
+
43
+ def parse(source, &block)
44
+ self.block = block
45
+
46
+ spec.parse(source)
47
+ Athena::Record.records
48
+ end
49
+
50
+ private
51
+
52
+ def build_config(config)
53
+ config.inject({}) { |hash, (field, v)|
54
+ if field.to_s =~ /^__/
55
+ hash.merge(field => v)
56
+ else
57
+ case v
58
+ when String, Array
59
+ elements = [*v]
60
+ v = {}
61
+ when Hash
62
+ elements = v[:elements] || v[:element].to_a
63
+
64
+ raise ArgumentError, "no elements specified for field #{field}" unless elements.is_a?(Array)
65
+ else
66
+ raise ArgumentError, "illegal value for field #{field}"
67
+ end
68
+
69
+ separator = v[:separator] || ', '
70
+
71
+ elements.each { |element|
72
+ verbose(:config) do
73
+ spit "#{field.to_s.upcase} -> #{element}"
74
+ end
75
+
76
+ (hash[element] ||= {})[field] = {
77
+ :string => v[:string] || ['%s'] * elements.size * separator,
78
+ :empty => v[:empty] || '<<EMPTY>>',
79
+ :elements => elements
80
+ }
81
+ }
82
+
83
+ hash
84
+ end
85
+ }
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,97 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of athena, the database file converter. #
5
+ # #
6
+ # Copyright (C) 2007 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # athena is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU General Public License as published by the Free Software #
15
+ # Foundation; either version 3 of the License, or (at your option) any later #
16
+ # version. #
17
+ # #
18
+ # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
21
+ # details. #
22
+ # #
23
+ # You should have received a copy of the GNU General Public License along #
24
+ # with athena. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ module Athena
30
+
31
+ class Record
32
+
33
+ include Util
34
+
35
+ @records = []
36
+
37
+ class << self
38
+
39
+ def records
40
+ @records
41
+ end
42
+
43
+ def [](field = nil, config = nil)
44
+ record = records.last
45
+ raise NoRecordError unless record
46
+
47
+ record.fill(field, config) if field && config
48
+ record
49
+ end
50
+
51
+ end
52
+
53
+ attr_reader :struct, :block, :id
54
+
55
+ def initialize(block, id = object_id.abs)
56
+ self.class.records << self
57
+
58
+ @struct = {}
59
+ @block = block
60
+ @id = id
61
+ end
62
+
63
+ def fill(field, config)
64
+ struct[field] ||= config.merge({ :values => Hash.new { |h, k| h[k] = [] } })
65
+ end
66
+
67
+ def update(element, data, field_config = nil)
68
+ if field_config
69
+ field_config.each { |field, config|
70
+ fill(field, config)
71
+ }
72
+ end
73
+
74
+ struct.each_key { |field|
75
+ verbose(:data) do
76
+ value = data.strip
77
+ spit "#{field.to_s.upcase}[#{element}] << #{value}" unless value.empty?
78
+ end
79
+
80
+ struct[field][:values][element] << data
81
+ }
82
+ end
83
+
84
+ def close
85
+ block ? block[self] : self
86
+ end
87
+
88
+ def to(format)
89
+ Athena::Formats[:out, format].convert(self)
90
+ end
91
+
92
+ class NoRecordError < StandardError
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,50 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of athena, the database file converter. #
5
+ # #
6
+ # Copyright (C) 2007 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # athena is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU General Public License as published by the Free Software #
15
+ # Foundation; either version 3 of the License, or (at your option) any later #
16
+ # version. #
17
+ # #
18
+ # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
21
+ # details. #
22
+ # #
23
+ # You should have received a copy of the GNU General Public License along #
24
+ # with athena. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ module Athena
30
+
31
+ module Util
32
+
33
+ extend self
34
+
35
+ def verbose(what, klass = self.class, &block)
36
+ if $_VERBOSE[what]
37
+ klass.send(:define_method, :spit) { |msg|
38
+ warn "*#{what}: #{msg}"
39
+ }
40
+ klass.send(:define_method, :indent) { |*level|
41
+ ' ' * (level.first || 0)
42
+ }
43
+
44
+ instance_eval(&block)
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,55 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of athena, the database file converter. #
5
+ # #
6
+ # Copyright (C) 2007 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # athena is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU General Public License as published by the Free Software #
15
+ # Foundation; either version 3 of the License, or (at your option) any later #
16
+ # version. #
17
+ # #
18
+ # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
21
+ # details. #
22
+ # #
23
+ # You should have received a copy of the GNU General Public License along #
24
+ # with athena. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ module Athena
30
+
31
+ module Version
32
+
33
+ MAJOR = 0
34
+ MINOR = 0
35
+ TINY = 1
36
+
37
+ class << self
38
+
39
+ # Returns array representation.
40
+ def to_a
41
+ [MAJOR, MINOR, TINY]
42
+ end
43
+
44
+ # Short-cut for version string.
45
+ def to_s
46
+ to_a.join('.')
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ VERSION = Version.to_s
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: athena
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1.53
7
+ date: 2007-10-11 00:00:00 +02:00
8
+ summary: Convert database files to various formats
9
+ require_paths:
10
+ - lib
11
+ email: jens.wille@uni-koeln.de
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Jens Wille
31
+ files:
32
+ - lib/athena.rb
33
+ - lib/athena/formats.rb
34
+ - lib/athena/version.rb
35
+ - lib/athena/util.rb
36
+ - lib/athena/record.rb
37
+ - lib/athena/parser.rb
38
+ - lib/athena/formats/sisis.rb
39
+ - lib/athena/formats/xml.rb
40
+ - lib/athena/formats/dbm.rb
41
+ - bin/athena
42
+ - COPYING
43
+ - README
44
+ - ChangeLog
45
+ - Rakefile
46
+ - example/sisis-ex.txt
47
+ - example/config.yaml
48
+ - example/example.xml
49
+ test_files: []
50
+
51
+ rdoc_options: []
52
+
53
+ extra_rdoc_files:
54
+ - README
55
+ - COPYING
56
+ - ChangeLog
57
+ executables:
58
+ - athena
59
+ extensions: []
60
+
61
+ requirements: []
62
+
63
+ dependencies:
64
+ - !ruby/object:Gem::Dependency
65
+ name: xmlstreamin
66
+ version_requirement:
67
+ version_requirements: !ruby/object:Gem::Version::Requirement
68
+ requirements:
69
+ - - ">"
70
+ - !ruby/object:Gem::Version
71
+ version: 0.0.0
72
+ version:
73
+ - !ruby/object:Gem::Dependency
74
+ name: ruby-nuggets
75
+ version_requirement:
76
+ version_requirements: !ruby/object:Gem::Version::Requirement
77
+ requirements:
78
+ - - ">"
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.0
81
+ version: