athena 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/athena/parser.rb CHANGED
@@ -3,32 +3,33 @@
3
3
  # #
4
4
  # A component of athena, the database file converter. #
5
5
  # #
6
- # Copyright (C) 2007-2010 University of Cologne, #
6
+ # Copyright (C) 2007-2011 University of Cologne, #
7
7
  # Albertus-Magnus-Platz, #
8
- # 50932 Cologne, Germany #
8
+ # 50923 Cologne, Germany #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@uni-koeln.de> #
12
12
  # #
13
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. #
14
+ # terms of the GNU Affero General Public License as published by the Free #
15
+ # Software Foundation; either version 3 of the License, or (at your option) #
16
+ # any later version. #
17
17
  # #
18
18
  # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
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. #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
21
+ # more details. #
22
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/>. #
23
+ # You should have received a copy of the GNU Affero General Public License #
24
+ # along with athena. If not, see <http://www.gnu.org/licenses/>. #
25
25
  # #
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- class Athena::Parser
29
+ module Athena
30
+ class Parser
30
31
 
31
- include Athena::Util
32
+ include Util
32
33
 
33
34
  DEFAULT_SEPARATOR = ', '
34
35
  DEFAULT_EMPTY = '<<EMPTY>>'
@@ -37,53 +38,53 @@ class Athena::Parser
37
38
 
38
39
  def initialize(config, spec)
39
40
  @config = build_config(config)
40
- @spec = Athena::Formats[:in, spec].new(self)
41
+ @spec = Formats[:in, spec].new(self)
41
42
  end
42
43
 
43
44
  def parse(source, &block)
44
45
  res = spec.parse(source, &block)
45
- res.is_a?(Numeric) ? res : Athena::Record.records
46
+ res.is_a?(Numeric) ? res : Record.records
46
47
  end
47
48
 
48
49
  private
49
50
 
50
51
  def build_config(config)
51
- config.inject({}) { |hash, (field, v)|
52
- if field.to_s =~ /^__/
53
- hash.merge(field => v)
52
+ hash = {}
53
+
54
+ config.each { |field, value|
55
+ if field.to_s =~ /\A__/
56
+ hash[field] = value
54
57
  else
55
- case v
58
+ case value
56
59
  when String, Array
57
- elements = [*v]
58
- v = {}
60
+ elements, value = [*value], {}
59
61
  when Hash
60
- elements = v[:elements] || v[:element].to_a
62
+ elements = value[:elements] || value[:element].to_a
61
63
 
62
64
  raise ArgumentError, "no elements specified for field #{field}" unless elements.is_a?(Array)
63
65
  else
64
66
  raise ArgumentError, "illegal value for field #{field}"
65
67
  end
66
68
 
67
- separator = v[:separator] || DEFAULT_SEPARATOR
69
+ separator = value[:separator] || DEFAULT_SEPARATOR
68
70
 
69
71
  elements.each { |element|
70
- verbose(:config) do
71
- spit "#{field.to_s.upcase} -> #{element}"
72
- end
72
+ verbose(:config) { spit "#{field.to_s.upcase} -> #{element}" }
73
73
 
74
74
  (hash[element] ||= {})[field] = {
75
- :string => v[:string] || ['%s'] * elements.size * separator,
76
- :empty => v[:empty] || DEFAULT_EMPTY,
75
+ :string => value[:string] || ['%s'] * elements.size * separator,
76
+ :empty => value[:empty] || DEFAULT_EMPTY,
77
77
  :elements => elements
78
78
  }
79
79
  }
80
-
81
- hash
82
80
  end
83
81
  }
82
+
83
+ hash
84
84
  end
85
85
 
86
86
  class ConfigError < StandardError
87
87
  end
88
88
 
89
+ end
89
90
  end
data/lib/athena/record.rb CHANGED
@@ -3,32 +3,35 @@
3
3
  # #
4
4
  # A component of athena, the database file converter. #
5
5
  # #
6
- # Copyright (C) 2007-2009 University of Cologne, #
6
+ # Copyright (C) 2007-2011 University of Cologne, #
7
7
  # Albertus-Magnus-Platz, #
8
- # 50932 Cologne, Germany #
8
+ # 50923 Cologne, Germany #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@uni-koeln.de> #
12
12
  # #
13
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. #
14
+ # terms of the GNU Affero General Public License as published by the Free #
15
+ # Software Foundation; either version 3 of the License, or (at your option) #
16
+ # any later version. #
17
17
  # #
18
18
  # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
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. #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
21
+ # more details. #
22
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/>. #
23
+ # You should have received a copy of the GNU Affero General Public License #
24
+ # along with athena. If not, see <http://www.gnu.org/licenses/>. #
25
25
  # #
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- class Athena::Record
29
+ require 'nuggets/integer/map'
30
30
 
31
- include Athena::Util
31
+ module Athena
32
+ class Record
33
+
34
+ include Util
32
35
 
33
36
  @records = []
34
37
 
@@ -50,12 +53,12 @@ class Athena::Record
50
53
 
51
54
  attr_reader :struct, :block, :id
52
55
 
53
- def initialize(id = nil, block = nil, _add_record = !block)
54
- @id = id || object_id.abs
56
+ def initialize(id = nil, block = nil, add = !block)
57
+ @id = id || object_id.map_positive
55
58
  @block = block
56
59
  @struct = {}
57
60
 
58
- add_record if _add_record
61
+ add_record if add
59
62
 
60
63
  if block_given?
61
64
  begin
@@ -67,21 +70,16 @@ class Athena::Record
67
70
  end
68
71
 
69
72
  def fill(field, config)
70
- struct[field] ||= config.merge({ :values => Hash.new { |h, k| h[k] = [] } })
73
+ struct[field] ||= config.merge(:values => Hash.new { |h, k| h[k] = [] })
71
74
  end
72
75
 
73
76
  def update(element, data, field_config = nil)
74
- if field_config
75
- field_config.each { |field, config|
76
- fill(field, config)
77
- }
78
- end
77
+ field_config.each { |field, config| fill(field, config) } if field_config
79
78
 
80
79
  struct.each_key { |field|
81
- verbose(:data) do
82
- value = data.strip
83
- spit "#{field.to_s.upcase}[#{element}] << #{value}" unless value.empty?
84
- end
80
+ verbose(:data) {
81
+ spit "#{field.to_s.upcase}[#{element}] << #{data.strip}" unless data.strip.empty?
82
+ }
85
83
 
86
84
  struct[field][:values][element] << data
87
85
  }
@@ -92,7 +90,7 @@ class Athena::Record
92
90
  end
93
91
 
94
92
  def to(format)
95
- Athena::Formats[:out, format].convert(self)
93
+ Formats[:out, format].convert(self)
96
94
  end
97
95
 
98
96
  private
@@ -104,4 +102,5 @@ class Athena::Record
104
102
  class NoRecordError < StandardError
105
103
  end
106
104
 
105
+ end
107
106
  end
data/lib/athena/util.rb CHANGED
@@ -3,30 +3,31 @@
3
3
  # #
4
4
  # A component of athena, the database file converter. #
5
5
  # #
6
- # Copyright (C) 2007-2009 University of Cologne, #
6
+ # Copyright (C) 2007-2011 University of Cologne, #
7
7
  # Albertus-Magnus-Platz, #
8
- # 50932 Cologne, Germany #
8
+ # 50923 Cologne, Germany #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@uni-koeln.de> #
12
12
  # #
13
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. #
14
+ # terms of the GNU Affero General Public License as published by the Free #
15
+ # Software Foundation; either version 3 of the License, or (at your option) #
16
+ # any later version. #
17
17
  # #
18
18
  # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
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. #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
21
+ # more details. #
22
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/>. #
23
+ # You should have received a copy of the GNU Affero General Public License #
24
+ # along with athena. If not, see <http://www.gnu.org/licenses/>. #
25
25
  # #
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- module Athena::Util
29
+ module Athena
30
+ module Util
30
31
 
31
32
  extend self
32
33
 
@@ -35,6 +36,7 @@ module Athena::Util
35
36
  klass.send(:define_method, :spit) { |msg|
36
37
  warn "*#{what}: #{msg}"
37
38
  }
39
+
38
40
  klass.send(:define_method, :indent) { |*level|
39
41
  ' ' * (level.first || 0)
40
42
  }
@@ -43,4 +45,5 @@ module Athena::Util
43
45
  end
44
46
  end
45
47
 
48
+ end
46
49
  end
@@ -1,51 +1,27 @@
1
- #--
2
- ###############################################################################
3
- # #
4
- # A component of athena, the database file converter. #
5
- # #
6
- # Copyright (C) 2007-2010 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::Version
30
-
31
- MAJOR = 0
32
- MINOR = 1
33
- TINY = 3
34
-
35
- class << self
36
-
37
- # Returns array representation.
38
- def to_a
39
- [MAJOR, MINOR, TINY]
40
- end
1
+ module Athena
2
+
3
+ module Version
4
+
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ TINY = 4
8
+
9
+ class << self
10
+
11
+ # Returns array representation.
12
+ def to_a
13
+ [MAJOR, MINOR, TINY]
14
+ end
15
+
16
+ # Short-cut for version string.
17
+ def to_s
18
+ to_a.join('.')
19
+ end
41
20
 
42
- # Short-cut for version string.
43
- def to_s
44
- to_a.join('.')
45
21
  end
46
22
 
47
23
  end
48
24
 
49
- Athena::VERSION = to_s
25
+ VERSION = Version.to_s
50
26
 
51
27
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: athena
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 4
10
+ version: 0.1.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jens Wille
@@ -9,39 +15,52 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-05 00:00:00 +01:00
13
- default_executable:
18
+ date: 2011-04-29 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: builder
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
23
31
  version: "0"
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: xmlstreamin
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
30
39
  requirements:
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
33
45
  version: "0"
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: ruby-nuggets
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
40
53
  requirements:
41
54
  - - ">="
42
55
  - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
56
+ hash: 15
57
+ segments:
58
+ - 0
59
+ - 6
60
+ - 4
61
+ version: 0.6.4
62
+ type: :runtime
63
+ version_requirements: *id003
45
64
  description: Convert database files to various formats.
46
65
  email: jens.wille@uni-koeln.de
47
66
  executables:
@@ -49,9 +68,9 @@ executables:
49
68
  extensions: []
50
69
 
51
70
  extra_rdoc_files:
71
+ - README
52
72
  - COPYING
53
73
  - ChangeLog
54
- - README
55
74
  files:
56
75
  - lib/athena/util.rb
57
76
  - lib/athena/record.rb
@@ -72,39 +91,43 @@ files:
72
91
  - example/config.yaml
73
92
  - example/example.xml
74
93
  - example/sisis-ex.txt
75
- has_rdoc: true
76
94
  homepage: http://prometheus.rubyforge.org/athena
77
95
  licenses: []
78
96
 
79
97
  post_install_message:
80
98
  rdoc_options:
81
99
  - --line-numbers
82
- - --inline-source
83
100
  - --main
84
101
  - README
85
102
  - --charset
86
103
  - UTF-8
87
- - --title
88
- - athena Application documentation
89
104
  - --all
105
+ - --title
106
+ - athena Application documentation (v0.1.4)
90
107
  require_paths:
91
108
  - lib
92
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
93
111
  requirements:
94
112
  - - ">="
95
113
  - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
96
117
  version: "0"
97
- version:
98
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
99
120
  requirements:
100
121
  - - ">="
101
122
  - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
102
126
  version: "0"
103
- version:
104
127
  requirements: []
105
128
 
106
129
  rubyforge_project: prometheus
107
- rubygems_version: 1.3.5
130
+ rubygems_version: 1.7.2
108
131
  signing_key:
109
132
  specification_version: 3
110
133
  summary: Convert database files to various formats.