Skip to content

Commit a3163d3

Browse files
authored
Merge pull request #14 from herwinw/base64
Allow compares between XMLRPC::Base64
2 parents e21b3de + d437338 commit a3163d3

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/xmlrpc/base64.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module XMLRPC # :nodoc:
1313
# You can use XMLRPC::Base64 on the client and server-side as a
1414
# parameter and/or return-value.
1515
class Base64
16+
include Comparable
1617

1718
# Creates a new XMLRPC::Base64 instance with string +str+ as the
1819
# internal string. When +state+ is +:dec+ it assumes that the
@@ -40,6 +41,11 @@ def encoded
4041
Base64.encode(@str)
4142
end
4243

44+
# Compare two base64 values, based on decoded string
45+
def <=>(other)
46+
return nil unless other.is_a?(self.class)
47+
decoded <=> other.decoded
48+
end
4349

4450
# Decodes string +str+ with base64 and returns that value.
4551
def Base64.decode(str)

test/test_base64.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
require 'test/unit'
3+
require 'xmlrpc/base64'
4+
5+
module TestXMLRPC
6+
class Test_Base64 < Test::Unit::TestCase
7+
def test_equals
8+
refute_equal(XMLRPC::Base64.new('foobar'), 'foobar')
9+
refute_equal(XMLRPC::Base64.new('foo'), XMLRPC::Base64.new('bar'))
10+
assert_equal(XMLRPC::Base64.new('foobar'), XMLRPC::Base64.new('foobar'))
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)