diff options
author | Kouhei Sutou <kou@clear-code.com> | 2019-05-25 17:47:41 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-08-04 11:55:37 +0900 |
commit | 5f78b138b10a6732676689f0f8690c1db16c1355 (patch) | |
tree | 0df730f6064bb54da62021d0c66dbe3b98afd771 /lib/rexml | |
parent | 6ef82943978ea5816a91c32e9ff822c73d1935f9 (diff) |
[ruby/rexml] xpath boolean: implement
https://github.com/ruby/rexml/commit/feb8ddb1ec
Diffstat (limited to 'lib/rexml')
-rw-r--r-- | lib/rexml/functions.rb | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 9c226d2cdf..4b46b8e678 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -315,18 +315,23 @@ module REXML end end - # UNTESTED - def Functions::boolean( object=nil ) - if object.kind_of? String - if object =~ /\d+/u - return object.to_f != 0 - else - return object.size > 0 - end - elsif object.kind_of? Array - object = object.find{|x| x and true} + def Functions::boolean(object=@@context[:node]) + case object + when true, false + object + when Float + return false if object.zero? + return false if object.nan? + true + when Numeric + not object.zero? + when String + not object.empty? + when Array + not object.empty? + else + object ? true : false end - return object ? true : false end # UNTESTED |