easydom 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/easydom.rb +49 -1
- metadata +10 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3df00636ac155a86dc33bd8dceff96632660d5fa45b3a751c6918ec4994c289b
|
4
|
+
data.tar.gz: f6eadbee9edf4c92f2aaafb554ae807c8a50f056deb0dcab426d3ce0ac1fe6db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bd63010b58cde78e990b534cdaf7374ff1f02d142ec27dbd1343cbd6741687cfdfbc585b33ff626d52d44ab94cee0afa78ee585a461f1dfa393fa0b8b98284d
|
7
|
+
data.tar.gz: b7cee04c71c285435b5aea1b5b05dfb22f019f3a2486426d8c54a1e93ac5dc2f6b85791c2c9552ed593f777751aaa2e3f9aba3a9e5a01bd7d4269cdbbe289769
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/easydom.rb
CHANGED
@@ -7,24 +7,72 @@ require 'free_dom'
|
|
7
7
|
|
8
8
|
class EasyDom
|
9
9
|
|
10
|
-
def initialize(obj, debug: false)
|
10
|
+
def initialize(obj=nil, debug: false, root: 'root')
|
11
11
|
|
12
12
|
@debug = debug
|
13
|
+
|
14
|
+
obj ||= "<#{root}/>"
|
13
15
|
|
14
16
|
@e = obj.is_a?(String) ? FreeDom.new(obj).root : obj
|
15
17
|
|
16
18
|
end
|
19
|
+
|
20
|
+
def ==(v)
|
21
|
+
@e.attributes.values.first.to_s == v
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s()
|
25
|
+
@e.attributes.values.first.to_s
|
26
|
+
end
|
17
27
|
|
18
28
|
def method_missing(sym, *args, &block)
|
19
29
|
|
20
30
|
puts "name: %s; args: %s" % [sym, args.inspect] if @debug
|
21
31
|
|
22
32
|
if @e.respond_to? sym then
|
33
|
+
|
23
34
|
puts 'attribute found' if @debug
|
24
35
|
@e.method(sym).call(*args)
|
36
|
+
|
37
|
+
elsif sym.to_s[-1] == '='
|
38
|
+
|
39
|
+
# assumes the 1st attribute it finds is the attribute to be set
|
40
|
+
|
41
|
+
puts '==' if @debug
|
42
|
+
e = @e.element(sym.to_s[0..-2])
|
43
|
+
|
44
|
+
if e.nil? then
|
45
|
+
|
46
|
+
attribute = sym[0..-2]
|
47
|
+
|
48
|
+
@e.instance_eval("def #{attribute}()
|
49
|
+
attributes[:#{attribute}]
|
50
|
+
end")
|
51
|
+
|
52
|
+
@e.instance_eval("def #{sym}(val)
|
53
|
+
attributes[:#{attribute}] = val
|
54
|
+
val
|
55
|
+
end")
|
56
|
+
|
57
|
+
return @e.method(sym).call(args.first)
|
58
|
+
end
|
59
|
+
|
60
|
+
attr = e.attributes.keys.first.to_s
|
61
|
+
|
62
|
+
puts 'attribute: ' + attr.inspect if @debug
|
63
|
+
|
64
|
+
e.method((attr + '=').to_sym).call(*args)
|
65
|
+
|
25
66
|
else
|
67
|
+
|
68
|
+
puts 'query element: ' + sym.to_s if @debug
|
26
69
|
e = @e.element(sym.to_s)
|
70
|
+
|
71
|
+
# if the element doesn't exist, create it
|
72
|
+
e = @e.add FreeDom::Element.new(sym, attributes: {}) unless e
|
73
|
+
|
27
74
|
EasyDom.new(e, debug: @debug) if e
|
75
|
+
|
28
76
|
end
|
29
77
|
|
30
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easydom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
GqWzjdQ5Dfb1ydCV6UC9Lu1hzIoAQVrkWlRlbX15SCvwTM+CbAAPFg3vwmKNi5T1
|
36
36
|
u695LgOX0KlDJi1766NJIYv8
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-
|
38
|
+
date: 2020-05-02 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: free_dom
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.1.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
46
|
+
version: '0.3'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.3.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 0.1.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version: '0.
|
56
|
+
version: '0.3'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.3.1
|
60
60
|
description:
|
61
61
|
email: james@jamesrobertson.eu
|
62
62
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|