roxo 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/roxo.rb +7 -8
  2. data/roxo.gemspec +1 -1
  3. metadata +3 -3
@@ -3,9 +3,7 @@ require 'libxml'
3
3
 
4
4
  # Ruby Objects as XML Objects
5
5
  class ROXO
6
- instance_methods.each do |meth|
7
- eval "undef #{meth}" unless [:__send__, :__id__, :object_id, :class, :send].include?(meth.to_sym)
8
- end
6
+ (instance_methods - %w{__send__ __id__ object_id class send}).each{|m|eval "undef #{m}"}
9
7
 
10
8
  include Comparable
11
9
 
@@ -22,10 +20,7 @@ class ROXO
22
20
 
23
21
  @raw, @name, @attributes = xml, xml.name, xml.attributes.to_h
24
22
  @children = xml.children.select(&:element?).group_by{|c|c.name.to_sym}
25
-
26
- text_value = xml.children.select(&:text?).map(&:to_s).reject(&:empty?).join
27
- cdata_value = xml.children.select(&:cdata?).map{|c|c.to_s.chomp(']]>').sub('<![CDATA[', '')}.join
28
- @value = text_value.empty? ? cdata_value : text_value
23
+ @value = xml.children.select{|e|e.text? or e.cdata?}.map{|e|e.to_s.chomp(']]>').sub('<![CDATA[','')}.join
29
24
  end
30
25
 
31
26
  def inspect
@@ -41,7 +36,11 @@ class ROXO
41
36
  end
42
37
 
43
38
  def method_missing(sym, *args)
44
- if @children[sym]
39
+ if terminal? # Proxy all method calls to the wrapped object.
40
+ return @value.send(sym, *args)
41
+ elsif sym.to_s[-1..-1]=="?" # re-dispatch without question mark, interpret result as a boolean.
42
+ return %w{yes true t y}.include?(send(sym.to_s[0..-2].to_sym, *args).downcase)
43
+ elsif @children[sym]
45
44
  return self.class.new(@children[sym].first)
46
45
  elsif @attributes[sym.to_s]
47
46
  return @attributes[sym.to_s]
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'roxo'
3
- gem.version = "0.1.3"
3
+ gem.version = '0.1.5'
4
4
 
5
5
  gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
6
6
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Burke Libbey
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-20 00:00:00 -05:00
17
+ date: 2010-04-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency