dxlite 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6268d88624bc2c37694a40bcd196ef5653e67ee4f49c2e3aa57762e0c24eaf74
4
- data.tar.gz: ff5277f2debc53311cc5b4d59eebb04d568199ff28df0e77bf4a731ddc89408d
3
+ metadata.gz: 17e3592686fa48db902f98d0d7dce8ed09b6bca4d2f42b36994bb940d47b5fd4
4
+ data.tar.gz: 6b2cb9ae5b94c25880b369e6bd558ca02005564bfaa96a810532963faba6fabd
5
5
  SHA512:
6
- metadata.gz: 4b639ab519450eee10073783acdcf0ed5c6cdf3013c54fb5251e06dc30f85147629d90572de01e322861e16443542e26f124390f3616b47c327191aafbed78da
7
- data.tar.gz: 36fc53ce6d3bb42ee0c07bd072b19cd83a61a72445b63f3c8b8de98dd20dc061cca69e71e1987ae0ead27d23286a901e719807f473b9e0b8bb25795deec647a1
6
+ metadata.gz: 241329fd8c70eb330cd70ea488c25f6fdbcc6ca0a062b3a3f3ce40bc43b65bb0207d4a25ce9ba8184ad457ebd574bbc4ff7025a6095d9d231eff6184b99ea80c
7
+ data.tar.gz: d57fac1b246db2e6915a4f8d4ce64341aba08a9e683a7a26d1692a13828756bafc75995664fde5369ff8e0ec9aafb7bf2ec50588c15ea6ded2c9d9b37e149ee6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,6 +7,7 @@ require 'json'
7
7
  require 'recordx'
8
8
  require 'rxfhelper'
9
9
 
10
+
10
11
  class DxLite
11
12
  using ColouredText
12
13
 
@@ -24,9 +25,12 @@ class DxLite
24
25
 
25
26
  when :file
26
27
 
27
- h = JSON.parse(buffer, symbolize_names: true)
28
+ h1 = JSON.parse(buffer, symbolize_names: true)
29
+ puts 'h1:' + h1.inspect if @debug
28
30
  @filepath = s
29
31
 
32
+ h = h1[h1.keys.first]
33
+
30
34
  @summary = h[:summary]
31
35
  @records = h[:records]
32
36
 
@@ -38,6 +42,13 @@ class DxLite
38
42
  end
39
43
 
40
44
  @schema = @summary[:schema]
45
+
46
+ summary_attributes = {
47
+ recordx_type: 'dynarex',
48
+ default_key: @schema[/(?<=\()\w+/],
49
+ }
50
+
51
+ @summary.merge!(summary_attributes)
41
52
 
42
53
  summary = @summary[:schema][/(?<=\[)[^\]]+/]
43
54
 
@@ -84,13 +95,29 @@ class DxLite
84
95
  def all()
85
96
 
86
97
  @records.map do |h|
87
- RecordX.new(h, self, h.object_id, h[:created], h[:last_modified])
98
+
99
+ puts 'h: ' + h.inspect if @debug
100
+ RecordX.new(h[:body], self, h[:id], h[:created],
101
+ h[:last_modified])
88
102
  end
89
103
 
90
104
  end
91
105
 
92
- def create(h)
93
- @records << h
106
+ def delete(id)
107
+ found = @records.find {|x| x[:id] == id}
108
+ @records.delete found if found
109
+ end
110
+
111
+ def create(h, id: nil, custom_attributes: {created: Time.now})
112
+
113
+ id ||= @records.map {|x| x[:id].to_i}.max.to_i + 1
114
+ h2 = custom_attributes
115
+ @records << {id: id.to_s, created: h2[:created], last_modified: nil, body: h}
116
+ end
117
+
118
+ def inspect()
119
+ "#<DxLite:%s @debug=%s, @summary=%s, ...>" % [object_id, @debug,
120
+ @summary.inspect]
94
121
  end
95
122
 
96
123
  # Parses 1 or more lines of text to create or update existing records.
@@ -104,7 +131,11 @@ class DxLite
104
131
  self.schema = "items/item(%s)" % cols.join(', ')
105
132
  end
106
133
 
107
- obj.each {|x| self.create x }
134
+ obj.each do |x|
135
+ puts 'x: ' + x.inspect if @debug
136
+ self.create x, id: nil
137
+ end
138
+
108
139
  return self
109
140
 
110
141
  end
@@ -113,13 +144,13 @@ class DxLite
113
144
  alias import parse
114
145
 
115
146
  def save(file=@filepath)
116
- File.write file, {summary: @summary, records: @records}.to_json
147
+ File.write file, to_json()
117
148
  end
118
149
 
119
150
  alias to_a records
120
151
 
121
- def to_xml()
122
-
152
+ def to_h()
153
+
123
154
  root_name = schema()[/^\w+/]
124
155
  record_name = schema()[/(?<=\/)[^\(]+/]
125
156
 
@@ -130,8 +161,38 @@ class DxLite
130
161
  records: @records.map {|h| {record_name.to_sym => h} }
131
162
  }
132
163
  }
164
+
165
+ end
166
+
167
+ def to_json(pretty: true)
168
+ pretty ? JSON.pretty_generate(to_h()) : to_h()
169
+ end
170
+
171
+ def to_xml()
172
+
173
+ root_name = schema()[/^\w+/]
174
+ record_name = schema()[/(?<=\/)[^\(]+/]
175
+
176
+ a = RexleBuilder.build do |xml|
177
+
178
+ xml.send(root_name.to_sym) do
179
+ xml.summary({}, @summary)
180
+ xml.records do
181
+
182
+ all().each do |x|
183
+
184
+ h = {id: x.id, created: x.created, last_modified: x.last_modified}
185
+ puts 'x.to_h: ' + x.to_h.inspect if @debug
186
+ xml.send(record_name.to_sym, h, x.to_h)
187
+
188
+ end
189
+
190
+ end
191
+ end
192
+ end
133
193
 
134
- Rexle.new(RexleBuilder.new(h, debug: false).to_a).xml pretty: true
194
+ Rexle.new(a).xml pretty: true
195
+
135
196
 
136
197
  end
137
198
 
@@ -146,8 +207,8 @@ class DxLite
146
207
  puts ('obj.class: ' + obj.class.inspect).debug
147
208
  end
148
209
 
149
- r = @records.find {|x| x.object_id == id}
150
- r.merge!(obj)
210
+ r = @records.find {|x| x[:id] == id}
211
+ r[:body].merge!(obj)
151
212
  end
152
213
 
153
214
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dxlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -103,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.3
106
+ rubyforge_project:
107
+ rubygems_version: 2.7.10
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Handles Dynarex documents (in JSON format) faster and with less overheads.
metadata.gz.sig CHANGED
Binary file