rexle 0.1.2 → 0.1.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/rexle.rb +25 -3
  2. metadata +2 -2
@@ -47,17 +47,25 @@ class Rexle
47
47
 
48
48
  items = raw_items.map do |x|
49
49
  name, value = x.split(/=/)
50
- [name, (value ? value[1..-2] : '')]
50
+ if value then
51
+ "h['%s'] == '%s'" % [name,value[1..-2]]
52
+ else
53
+ name
54
+ end
51
55
  end
56
+
57
+ attr_search = items.join(' ')
58
+ puts 'attr_search : ' + attr_search
59
+
52
60
  end
53
61
 
54
62
  return_elements = @child_lookup.map.with_index.select {|x| x[0][0] == element_name}
55
63
 
56
64
  if return_elements.length > 0 then
57
65
  if a.empty? then
58
- return_elements.map{|x| @child_elements[x.last]}
66
+ return_elements.map {|x| filter(x, attr_search)}.compact!
59
67
  else
60
- return_elements.map{|x| @child_elements[x.last].xpath a.join}.flatten
68
+ return_elements.map {|x| filter(x, attr_search){|e| e.xpath a.join }}.flatten
61
69
  end
62
70
  end
63
71
  end
@@ -66,6 +74,20 @@ class Rexle
66
74
  @attributes
67
75
  end
68
76
 
77
+
78
+ def filter(raw_element, attr_search, &blk)
79
+
80
+ x = raw_element
81
+ e = @child_elements[x.last]
82
+
83
+ if attr_search.empty? then
84
+ block_given? ? blk.call(e) : e
85
+ else
86
+ h = x[0][1]
87
+ block_given? ? blk.call(e) : e if h and eval(attr_search)
88
+ end
89
+ end
90
+
69
91
  end
70
92
 
71
93
  def scan_element(a)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-10-17 00:00:00 +01:00
12
+ date: 2010-10-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15