polyrex 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/polyrex.rb +28 -25
  2. metadata +1 -1
data/lib/polyrex.rb CHANGED
@@ -17,32 +17,33 @@ class Polyrex
17
17
  schema_rpath = schema.gsub(/\[[^\]]+\]/,'')
18
18
  @recordx = schema_rpath.split('/')
19
19
 
20
- root_format_mask = @format_masks.shift
21
- field_names = root_format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
22
- @root_name = @recordx.shift
23
-
24
- summary = field_names.map {|x| "<%s/>" % x}.join
25
- @doc = Document.new("<%s><summary>%s</summary></%s>" % [@root_name, summary, @root_name])
26
-
20
+ if @format_masks.length == @recordx.length then
21
+ root_format_mask = @format_masks.shift
22
+ field_names = root_format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
23
+ summary = field_names.map {|x| "<%s/>" % x}.join
24
+ end
27
25
  #----
28
26
 
29
27
  @schema = schema
30
28
 
31
29
  @id = '1'
32
- #a = @schema.split('/')
33
- a = @recordx.clone
34
- #@root_name = a[0]
35
-
36
- #@doc = Document.new "<%s><summary/><records/></%s>" % ([@root_name] * 2)
37
- @parent_node = XPath.first(@doc.root,'records')
30
+ a = @schema.split('/')
38
31
 
39
- #@rpaths = (a.length).times.inject({}) {|r| r.merge ({a.join('/').gsub(/\[[^\]]+\]/,'') => a.pop}) }
40
- @rpaths = (@recordx.length).times.inject({}) {|r| r.merge ({a.join('/') => a.pop}) }
32
+ @rpaths = (a.length).times.inject({}) {|r| r.merge ({a.join('/').gsub(/\[[^\]]+\]/,'') => a.pop}) }
41
33
 
42
- names = @rpaths.to_a[0..-2].map {|k,v| [v[/.[^\[]+/], k]}
34
+ names = @rpaths.to_a[0..-2].map {|k,v| [v[/[^\[]+/], k]}
35
+ attach_create_handlers(names)
43
36
 
37
+ @root_name = @recordx.shift
38
+
39
+ @doc = Document.new("<%s><summary>%s</summary><records/></%s>" % [@root_name, (summary || '') , @root_name])
40
+ @parent_node = XPath.first(@doc.root,'records')
41
+
42
+ end
43
+
44
+ def attach_create_handlers(names)
44
45
  names[0..-2].each do |name, xpath|
45
- self.instance_eval(
46
+ self.instance_eval(
46
47
  %Q(
47
48
  def create_#{name}(params)
48
49
  create_node(@parent_node, @rpaths['#{xpath}'], params)
@@ -62,9 +63,9 @@ def create_#{name}(params)
62
63
  self
63
64
  end
64
65
  ))
65
-
66
+
66
67
  end
67
-
68
+
68
69
  # -- start of crud methods --
69
70
  def valid_creation?()
70
71
 
@@ -125,7 +126,12 @@ end
125
126
  out = scan_link(new_a)
126
127
 
127
128
  records = Document.new("<records>%s</records>" % out)
128
- @doc.root.add records
129
+ doc_records = XPath.first(@doc.root, 'records')
130
+
131
+ records.each do |record|
132
+ doc_records.add record
133
+ end
134
+
129
135
  end
130
136
 
131
137
  def build_tree(a, new_a, prev_indent, history=[])
@@ -170,18 +176,15 @@ end
170
176
 
171
177
  line= x[0].reverse.map(&:strip).join
172
178
 
173
- puts 'format_masks ' + @format_masks.inspect
174
179
  @field_names = @format_masks[i].to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
175
- puts 'field_names : ' + @field_names.inspect
176
180
 
177
181
  t = @format_masks[i].to_s.gsub(/\[!(\w+)\]/, '(.*)').sub(/\[/,'\[').sub(/\]/,'\]')
178
- puts 'line : ' + line.inspect
179
182
  field_values = line.match(/#{t}/).captures
180
- puts 'field_values : ' + field_values.inspect
181
183
 
182
184
  fields = @field_names.zip(field_values).map{|name, value| "<%s>%s</%s>" % [name,value,name]}.join
183
185
 
184
- out << indent + "<#{tag_name}><summary>#{fields}</summary>"
186
+ @id = (@id.to_i + 1).to_s
187
+ out << indent + "<#{tag_name} id='#{@id}'><summary>#{fields}</summary>"
185
188
  if x.length > 1 and x[0].is_a? Array then
186
189
  #i2 += ' '
187
190
  out << indent + "<records>\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors: []
7
7