xmlcodec 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +10 -4
  2. data/lib/XMLElement.rb +48 -30
  3. metadata +9 -7
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  PKG_NAME = 'xmlcodec'
2
- PKG_VERSION = '0.0.2'
2
+ PKG_VERSION = '0.0.3'
3
3
 
4
4
  require 'rake'
5
5
  require 'rake/testtask'
@@ -18,6 +18,9 @@ PKG_FILES = FileList[TEST_FILES,
18
18
  'LICENSE',
19
19
  'Rakefile']
20
20
 
21
+ RDOC_OPTIONS = ['-S', '-w 2', '-N']
22
+ RDOC_EXTRA_FILES = ['README']
23
+
21
24
  spec = Gem::Specification.new do |s|
22
25
  s.platform = Gem::Platform::RUBY
23
26
  s.summary = "Generic Importer/Exporter of XML formats"
@@ -29,6 +32,9 @@ spec = Gem::Specification.new do |s|
29
32
  s.require_path = 'lib'
30
33
  s.autorequire = 'rake'
31
34
  s.files = PKG_FILES
35
+ s.has_rdoc = true
36
+ s.rdoc_options = RDOC_OPTIONS
37
+ s.extra_rdoc_files = RDOC_EXTRA_FILES
32
38
  s.description = <<EOF
33
39
  A library that eases the creation of XML importers and exporters for ruby.
34
40
  EOF
@@ -50,10 +56,10 @@ end
50
56
  Rake::RDocTask.new do |rd|
51
57
  rd.main = "README"
52
58
  rd.name = :docs
53
- rd.rdoc_files.include("README", "lib/**/*.rb")
54
- rd.rdoc_dir = 'doc'
59
+ rd.rdoc_files.include(RDOC_EXTRA_FILES, CODE_FILES)
60
+ rd.rdoc_dir = 'web/doc'
55
61
  rd.title = "#{PKG_NAME} API"
56
- rd.options = ['-S', '-w 2', '-N']
62
+ rd.options = RDOC_OPTIONS
57
63
  end
58
64
 
59
65
  task :stats do
data/lib/XMLElement.rb CHANGED
@@ -27,6 +27,7 @@ module XMLCodec
27
27
  # rough in certain places. Changes will surely be made.
28
28
  class XMLElement
29
29
  INDENT_STR = ' '
30
+ CACHE = {}
30
31
 
31
32
  attr_accessor :element_id, :parent_id, :__xml_text
32
33
  attr_accessor :__parent
@@ -80,22 +81,35 @@ module XMLCodec
80
81
  }
81
82
  end
82
83
 
83
- # Iterates over all of the object's XML subelements
84
- def each_subel
85
- self.class.xmlsubels.each {|name| yield name}
84
+ # Iterates over the object's XML subelements
85
+ def self.each_subel
86
+ if not self.instance_variables.index("@__subel_names")
87
+ names = []
88
+ # Iterate all the superclasses that are still children of XMLElement
89
+ # and iterate each of the subelements
90
+ c = self
91
+ while c.ancestors.index(XMLCodec::XMLElement)
92
+ names += c.xmlsubels
93
+ c = c.superclass
94
+ end
95
+ @__subel_names = names
96
+ end
97
+ @__subel_names.each {|name| yield name}
86
98
  end
87
99
 
88
100
  # Iterate all the superclasses that are still children of XMLElement
89
101
  # and check if any of them have the subelement mult defined
90
- def subel_mult?(element)
91
- c = self.class
92
- while c.ancestors.index(XMLCodec::XMLElement)
93
- if c.xmlsubelmultiples.index(element)
94
- return true
102
+ def self.subel_mult?(element)
103
+ if not self.instance_variables.index("@__subel_mult_names")
104
+ names = []
105
+ c = self
106
+ while c.ancestors.index(XMLCodec::XMLElement)
107
+ names += c.xmlsubelmultiples
108
+ c = c.superclass
95
109
  end
96
- c = c.superclass
110
+ @__subel_mult_names = names
97
111
  end
98
- return false
112
+ return @__subel_mult_names.index(element)? true : false
99
113
  end
100
114
 
101
115
  # Iterate all the superclasses that are still children of XMLElement
@@ -115,19 +129,25 @@ module XMLCodec
115
129
  end
116
130
 
117
131
  # Iterates over the object's XML atributes
118
- def each_attr
119
- # Iterate all the superclasses that are still children of EADElement
120
- # and iterate each of the attributes
121
- c = self.class
122
- while c.ancestors.index(XMLCodec::XMLElement)
123
- c.xmlattrs.each {|name| yield name}
124
- c = c.superclass
132
+ def self.each_attr
133
+ if not self.instance_variables.index("@__attr_names")
134
+ names = []
135
+ # Iterate all the superclasses that are still children of EADElement
136
+ # and iterate each of the attributes
137
+ c = self
138
+ while c.ancestors.index(XMLCodec::XMLElement)
139
+ names += c.xmlattrs
140
+ c = c.superclass
141
+ end
142
+ @__attr_names = names
125
143
  end
144
+
145
+ @__attr_names.each {|name| yield name}
126
146
  end
127
147
 
128
148
  # Creates the XML for the atributes
129
149
  def create_xml_attr(parent)
130
- each_attr do |a|
150
+ self.class.each_attr do |a|
131
151
  value = self.send(a)
132
152
  if value
133
153
  parent.add_attribute(a.to_s, value)
@@ -138,7 +158,7 @@ module XMLCodec
138
158
  # returns a string with the opening tag for the element
139
159
  def create_open_tag
140
160
  attrs = {}
141
- each_attr do |a|
161
+ self.class.each_attr do |a|
142
162
  value = self.send(a)
143
163
  if value
144
164
  attrs[a.to_s] = value
@@ -203,7 +223,7 @@ module XMLCodec
203
223
 
204
224
  # Creates the XML subelements
205
225
  def create_xml_subel(parent)
206
- each_subel do |a|
226
+ self.class.each_subel do |a|
207
227
  if value = self.send(a)
208
228
  value.create_xml(parent)
209
229
  end
@@ -244,9 +264,9 @@ module XMLCodec
244
264
  def each_subelement
245
265
  arr = []
246
266
 
247
- each_subel do |a|
267
+ self.class.each_subel do |a|
248
268
  if value = self.send(a)
249
- if subel_mult? a
269
+ if self.class.subel_mult? a
250
270
  value.each {|e| arr << e}
251
271
  else
252
272
  arr << value
@@ -255,7 +275,7 @@ module XMLCodec
255
275
  end
256
276
 
257
277
  if has_subelements?
258
- @subelements.each{|e| arr << e}
278
+ self.subelements.each{|e| arr << e}
259
279
  end
260
280
 
261
281
  arr.each {|e| yield e}
@@ -264,9 +284,9 @@ module XMLCodec
264
284
  public
265
285
  # Remove the given subelement from the element
266
286
  def delete_element(element)
267
- each_subel do |a|
287
+ self.class.each_subel do |a|
268
288
  value = self.send(a)
269
- if subel_mult? a
289
+ if self.class.subel_mult? a
270
290
  value.delete_element(element)
271
291
  else
272
292
  self.send(a.to_s+'=', nil) if value == element
@@ -387,10 +407,8 @@ module XMLCodec
387
407
 
388
408
  # add the attributes passed as a hash to the element
389
409
  def add_attr(attrs)
390
- each_attr do |a|
391
- if value = attrs[a.to_s]
392
- self.send("#{a}=", value)
393
- end
410
+ attrs.each do |name, value|
411
+ self.send("#{name}=", value)
394
412
  end
395
413
  end
396
414
 
@@ -405,7 +423,7 @@ module XMLCodec
405
423
  def add_subel(children)
406
424
  children.each do |c|
407
425
  if subel_name = get_subel(c.class)
408
- if subel_mult? subel_name
426
+ if self.class.subel_mult? subel_name
409
427
  self.send(subel_name) << c
410
428
  else
411
429
  self.send(subel_name.to_s+'=', c)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: xmlcodec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2006-05-18 00:00:00 +01:00
6
+ version: 0.0.3
7
+ date: 2006-05-29 00:00:00 +01:00
8
8
  summary: Generic Importer/Exporter of XML formats
9
9
  require_paths:
10
10
  - lib
@@ -15,7 +15,7 @@ description: A library that eases the creation of XML importers and exporters fo
15
15
  autorequire: rake
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: false
18
+ has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
21
  - - ">"
@@ -45,10 +45,12 @@ files:
45
45
  - Rakefile
46
46
  test_files: []
47
47
 
48
- rdoc_options: []
49
-
50
- extra_rdoc_files: []
51
-
48
+ rdoc_options:
49
+ - -S
50
+ - -w 2
51
+ - -N
52
+ extra_rdoc_files:
53
+ - README
52
54
  executables: []
53
55
 
54
56
  extensions: []