rexleparser 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rexleparser.rb +22 -5
  2. metadata +2 -2
data/lib/rexleparser.rb CHANGED
@@ -15,8 +15,21 @@ class RexleParser
15
15
  @a
16
16
  end
17
17
 
18
+ def to_s()
19
+ name, value, attributes, *remaining = @a
20
+ [value.strip, scan_a(remaining)].flatten.join(' ')
21
+ end
22
+
18
23
  private
19
-
24
+
25
+ def scan_a(a)
26
+ a.inject([]) do |r, x|
27
+ name, value, attributes, *remaining = x
28
+ text_remaining = scan_a remaining if remaining
29
+ r << value.strip << text_remaining if value
30
+ end
31
+ end
32
+
20
33
  def scan_element(a)
21
34
 
22
35
  a.shift until a[0] == '<' and a[1] != '/' or a.length < 1
@@ -50,12 +63,15 @@ class RexleParser
50
63
  if a[i-1] == '/' then
51
64
 
52
65
  raw_values << a.shift until (a[0] + a[1..-1].join.strip[0]) == '/>'
53
- puts 'raw_values: ' + raw_values
66
+
54
67
  a.shift until a[0] == '<' or a.length < 1
55
68
  raw_values.strip!
56
69
 
57
70
  attributes = get_attributes(raw_values) if raw_values.length > 0
71
+
58
72
  element = [name, '', attributes]
73
+
74
+ element
59
75
  else
60
76
 
61
77
  raw_values << a.shift until a[0] == '<'
@@ -89,11 +105,12 @@ class RexleParser
89
105
  #puts 'element: ' + element.inspect
90
106
  end
91
107
  end
92
-
108
+
109
+ element
93
110
  end
94
111
 
95
- #return remaining ? [element, remaining] : element
96
- if remaining.nil? then
112
+
113
+ if remaining.nil? or remaining.strip.empty? then
97
114
  return element
98
115
  else
99
116
  return [element, remaining]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rexleparser
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.7
5
+ version: 0.2.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-24 00:00:00 +01:00
13
+ date: 2011-08-03 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16