polyrex-objects 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/polyrex-objects.rb +13 -1
- metadata +12 -3
data/lib/polyrex-objects.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# file: polyrex-objects.rb
|
4
4
|
|
5
5
|
require 'rexml/document'
|
6
|
+
require 'polyrex-createobject'
|
6
7
|
|
7
8
|
class PolyrexObjects
|
8
9
|
include REXML
|
@@ -22,7 +23,7 @@ class PolyrexObjects
|
|
22
23
|
classx = []
|
23
24
|
classx << "class #{name.capitalize}"
|
24
25
|
classx << "include REXML"
|
25
|
-
classx << "def initialize(node); @node = node; end"
|
26
|
+
classx << "def initialize(node, id=nil); @id=id; @node = node; @create = PolyrexCreateObject.new('#{schema}'); end"
|
26
27
|
fields.each do |field|
|
27
28
|
classx << "def #{field}; XPath.first(@node, 'summary/#{field}/text()'); end"
|
28
29
|
classx << "def #{field}=(text); XPath.first(@node, 'summary/#{field}').text = text; end"
|
@@ -40,9 +41,18 @@ class PolyrexObjects
|
|
40
41
|
def records()
|
41
42
|
XPath.each(@node, 'records/*') {|record| yield(#{@class_names[i]}.new(record))}
|
42
43
|
end
|
44
|
+
|
45
|
+
def create(id=nil)
|
46
|
+
@create.id = id || @id
|
47
|
+
@id = @id.to_i + 1
|
48
|
+
@create.record = @node
|
49
|
+
@create
|
50
|
+
end
|
51
|
+
|
43
52
|
}"
|
44
53
|
end
|
45
54
|
|
55
|
+
|
46
56
|
end
|
47
57
|
|
48
58
|
def to_a
|
@@ -52,4 +62,6 @@ class PolyrexObjects
|
|
52
62
|
def to_h
|
53
63
|
Hash[self.to_a.map {|x| [x.name[/\w+$/], x]}]
|
54
64
|
end
|
65
|
+
|
66
|
+
|
55
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -11,8 +11,17 @@ cert_chain: []
|
|
11
11
|
|
12
12
|
date: 2010-06-06 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: polyrex-createobject
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description:
|
17
26
|
email:
|
18
27
|
executables: []
|