radix-firstbanco 2.2.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGZlODI1YTRlZjI2MTZhNGZkYTA2NzhiM2MyNzE4NTc2NmFjNjJkNg==
5
+ data.tar.gz: !binary |-
6
+ ZTg3ZmRkOGIzMmJlZjA3ZGJhM2U5Zjg2MDM3NWJhMDJkMjZmMzhkMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Y2M1ZDY0OGNlMzU5NTA3Y2ZhNzBkN2VhNTNhNzQ0NDdlOWY1YzRjMWM4Nzhk
10
+ ZDQ3NTE4MGEzNmZhZTlkMjNmMGU2ZGIxYTBjYTBjMWY3OGZlODk3YTgwMTFj
11
+ ZTAyM2YzMWZmMGI1NmVmY2U2NTI4MDQ0MzE2MzM2ZWZlYmI1NmI=
12
+ data.tar.gz: !binary |-
13
+ YTg3ZmEyOGI3MTkzMTNiYmZhMTZlYTk3YTdjZGY5NDliOTk1MjkxNTg2YTlh
14
+ Y2NmOTM2NDFhYTM3MTNlNjJhMjFhODlkMDcxNWY1ZDhiMjA5ZDE3MDFjYmZj
15
+ Mjg3ZWJjMTI3YWM0NWY2ODg3NTA1ZjhkMDYxMGEwMzY1MTBkOGI=
data/.index ADDED
@@ -0,0 +1,59 @@
1
+ ---
2
+ revision: 2013
3
+ type: ruby
4
+ sources:
5
+ - var
6
+ authors:
7
+ - name: Thomas Sawyer
8
+ email: transfire@gmail.com
9
+ organizations: []
10
+ requirements:
11
+ - groups:
12
+ - build
13
+ development: true
14
+ name: ergo
15
+ - groups:
16
+ - test
17
+ development: true
18
+ name: qed
19
+ - groups:
20
+ - test
21
+ development: true
22
+ name: ae
23
+ conflicts: []
24
+ alternatives: []
25
+ resources:
26
+ - type: home
27
+ uri: http://rubyworks.github.com/radix
28
+ label: Homepage
29
+ - type: code
30
+ uri: http://github.com/rubyworks/radix
31
+ label: Source Code
32
+ - type: mail
33
+ uri: http://groups.google.com/groups/rubyworks-mailinglist
34
+ label: Mailing List
35
+ - type: bugs
36
+ uri: http://github.com/rubyworks/radix/issues
37
+ label: Issue Tracker
38
+ repositories:
39
+ - name: upstream
40
+ scm: git
41
+ uri: git://github.com/rubyworks/radix.git
42
+ categories: []
43
+ copyrights:
44
+ - holder: ''
45
+ year: '2009'
46
+ license: BSD-2-Clause
47
+ customs: []
48
+ paths:
49
+ lib:
50
+ - lib
51
+ created: '2009-07-01'
52
+ summary: Convert to and from any base.
53
+ title: Radix
54
+ version: 2.2.0
55
+ name: radix
56
+ description: ! "Radix is a very easy to use Ruby library for converting numbers to
57
+ and from\nany base. It supports both Integer, Float and Rational numbers, as well
58
+ as \nrepresentational string-notations that need not be in ASCII order."
59
+ date: '2013-03-20'
@@ -0,0 +1,8 @@
1
+ --title Radix
2
+ --readme README.md
3
+ --protected
4
+ --private
5
+ lib
6
+ -
7
+ *.md
8
+ *.txt
@@ -0,0 +1,95 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 2.2.0 / 2013-03-20
4
+
5
+ Good documentation is so under-addressed by most developers that we really
6
+ have to roll out the bright lights when someone comes along and takes
7
+ up the time consuming mantle of documenting an API in complete detail.
8
+ This is exactly what happened with Radix this last month. A coder going
9
+ by the unassuming handle, **douglascodes**, announced his desire to
10
+ document Radix and proceeded to do so until YARD pronounced 100%
11
+ completeness. Hey, we think that is worth of a whole version bump and
12
+ a big shout-out for Douglas!
13
+
14
+ Changes:
15
+
16
+ * 100% API documentation coverage. (douglascodes)
17
+
18
+
19
+ ## 2.1.1 / 2013-02-06
20
+
21
+ Minor release to fix gemspec. Which, alas, Bundler cannot do without.
22
+
23
+ Changes:
24
+
25
+ * Update .gemspec file for latest indexer.
26
+
27
+
28
+ ## 2.1.0 / 2013-01-31
29
+
30
+ This release fixes two bugs. The first caused base conversions of `0`
31
+ to return an empty string. Second, the `Float#to_r` extension was
32
+ using multiplication when it should have been using power.
33
+ Ruby 1.9 includes `Float#to_r` though, so the use of Radix's *fixed*
34
+ core extension is conditioned on Ruby 1.8 now. This release also
35
+ updates the build a bit, primarily converting RDoc documents to
36
+ Markdown.
37
+
38
+ Changes:
39
+
40
+ * Fix issue #5, Float#to_r using times instead of power. (simonratner)
41
+ * Fix issue #4, zero converts to empty string. (bbasata)
42
+ * Convert RDoc documents to Markdown.
43
+
44
+
45
+ ## 2.0.1 / 2011-10-23
46
+
47
+ This release is simply an administrative release to update the project
48
+ build configuration. The functionality of the library itself has not
49
+ changed. This release also transitions the project to the BSD-2-Clause
50
+ license.
51
+
52
+ Changes:
53
+
54
+ * Modernize build configuration.
55
+ * Switch to BSD-2-Clause license.
56
+
57
+
58
+ ## 2.0.0 / 2010-10-31
59
+
60
+ Radix::Number has been deprecate in favor of three separate classes,
61
+ Radix::Integer, Radix::Float and Radix::Rational. In addition
62
+ implementation of these classes has been reworked.
63
+
64
+ Changes:
65
+
66
+ * Deprecate Radix::Number
67
+ * Add Radix::Integer
68
+ * Add Radix::Float
69
+ * Add Radix::Rational
70
+
71
+
72
+ ## 1.1.0 / 2010-09-03
73
+
74
+ Radix now provides an actual Numeric subclass, Radix::Number, that stores
75
+ the base and can be used like any other Numeric object. This makes it very
76
+ easy to convert and manipulate numbers in any base. The implementation is still
77
+ a bit nascent. For the moment, it only supports the most basic math operators
78
+ and only handles integer values, but future releases will continue to expand
79
+ on it's capabilities.
80
+
81
+ Changes:
82
+
83
+ * Add Radix::Number to handle bases like any other numeric.
84
+ * Rename Radix class to Radix::Base.
85
+
86
+
87
+ ## 1.0.0 / 2009-07-01
88
+
89
+ This is the initial stand-alone release of Radix,
90
+ ported from the basex.rb library of Ruby Facets.
91
+
92
+ Changes:
93
+
94
+ * Happy Birthday!
95
+
@@ -0,0 +1,23 @@
1
+ BSD-2-Clause License
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
14
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
@@ -0,0 +1,100 @@
1
+ # Radix
2
+
3
+ [Website](http://rubyworks.github.com/radix) ·
4
+ [Report Issue](http://github.com/rubyworks/radix/issues) ·
5
+ [Source Code](http://github.com/rubyworks/radix)    
6
+ [![Build Status](https://secure.travis-ci.org/rubyworks/radix.png)](http://travis-ci.org/rubyworks/radix)
7
+ [![Gem Version](https://badge.fury.io/rb/radix.png)](http://badge.fury.io/rb/radix)    
8
+ [![Flattr Me](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
9
+
10
+
11
+ Radix is a very easy to use Ruby library for converting numbers to and from
12
+ any base. It supports both Integer, Float and Rational numbers, as well as
13
+ representational string-notations that need not be in ASCII order.
14
+
15
+
16
+ ## Features
17
+
18
+ * Convert to and from any base.
19
+ * Convert Integers, Floats and Rational numbers.
20
+ * Define custom encoding and character sets.
21
+ * Can be used to encode/decode bytecode strings.
22
+ * Very intuitive API.
23
+
24
+
25
+ ## Usage
26
+
27
+ Base conversions with ASCII ordered notations are easy in Ruby.
28
+
29
+ ```ruby
30
+ 255.to_s(16) #=> "FF"
31
+
32
+ "FF".to_i(16) #=> 255
33
+ ```
34
+
35
+ But Ruby reaches it's limit at base 36.
36
+
37
+ ```ruby
38
+ 255.to_s(37) #=> Error
39
+ ```
40
+
41
+ Radix provides the means of converting to and from any base.
42
+
43
+ For example, a number in base 256 can be represented by the array `[100, 10]`
44
+ (`100**256 + 10**1`) and can be convert to base 10.
45
+
46
+ ```ruby
47
+ [100,10].b(256).to_a(10) #=> [2,5,6,1,0]
48
+ ```
49
+
50
+ Or, to get a string representation for any base up to 62.
51
+
52
+ ```ruby
53
+ [100,10].b(256).to_s(10) #=> "25610"
54
+ ```
55
+
56
+ A string representation of a number can be converted too, again,
57
+ up to base 62.
58
+
59
+ ```ruby
60
+ "10".b(62).to_s(10) #=> "62"
61
+ ```
62
+
63
+ To use a custom character set, use an array of characters as the base
64
+ rather than an integer. For example we can convert a base 10 number
65
+ to another base 10 number using a different encoding.
66
+
67
+ ```ruby
68
+ base = [:Q, :W, :E, :R, :T, :Y, :U, :I, :O, :U]
69
+
70
+ "10".b(10).to_a(base) #=> [:W, :Q]
71
+ ```
72
+
73
+ To learn more have a look at the [QED Demo](http://rubydoc.info/gems/radix/file/DEMO.md).
74
+
75
+
76
+ ## Installing
77
+
78
+ To install with RubyGems simply open a console and type:
79
+
80
+ $ gem install radix
81
+
82
+ Radix follows [Ruby Setup](http://rubyworks.github.com/setup) package standard
83
+ so it can also be installed in an FHS compliant manner using setup.rb.
84
+
85
+
86
+ ## Special Thanks
87
+
88
+ Special thanks to **douglascodes** for taking the time to fully document
89
+ Radix's API. Documentation is an under-addressed and time-consuming affair,
90
+ so your contribution is greatly appreciated. Thank you, Douglas!
91
+
92
+
93
+ ## Copyrights
94
+
95
+ Copyright (c) 2009 Rubyworks
96
+
97
+ This program is distributable in accordance with the *BSD-2-Clause* license.
98
+
99
+ See LICENSE.txt for details.
100
+
@@ -0,0 +1,46 @@
1
+ # Synopsis
2
+
3
+ Radix provides the means of converting to and from any base.
4
+ For example, a number in base 256 can be represented by the array [100, 10]
5
+ (ie. 100**256 + 10**1) and easily converted to base 10.
6
+
7
+ [100,10].b(256).to_i #=> 25610
8
+
9
+ We can get an Array representation as well.
10
+
11
+ [100,10].b(256).to_a(10) #=> [2,5,6,1,0]
12
+ [100,10].b(256).to_a(62) #=> [6,41,4]
13
+ [100,10].b(256).to_a(64) #=> [6,16,10]
14
+
15
+ To get a String representation for any base use #to_s.
16
+
17
+ [100,10].b(256).to_s(10) #=> "25610"
18
+ [100,10].b(256).to_s(62) #=> "6 41 4"
19
+ [100,10].b(256).to_s(64) #=> "6 16 10"
20
+
21
+ Notice that anything above base 10 is seperated by a space divider. The divider
22
+ can be changed by providing a second argument.
23
+
24
+ [100,10].b(256).to_s(64, ':') #=> "6:16:10"
25
+
26
+ A string representation of a number can be converted upto base 62 (B62).
27
+
28
+ "10".b(62).to_s(10) #=> "62"
29
+ "zz".b(62).to_s(10) #=> "3843"
30
+
31
+ To encode a number with a base greater than 10, use an Array base. Radix
32
+ provides a built-in set of these, such as `BASE::B62`.
33
+
34
+ [100,10].b(256).to_s(Radix::BASE::B62) #=> "6f4"
35
+
36
+ To use a custom character set, use an array of characters as the base
37
+ rather than an integer. For example we can convert a base 10 number
38
+ to another base 10 number but useing a different encoding.
39
+
40
+ base = %w[Q W E R T Y U I O U]
41
+
42
+ "10".b(10).to_a(base) #=> ["W", "Q"]
43
+
44
+ "10".b(10).to_s(base) #=> "WQ"
45
+
46
+ All of the above holds equally for floating point numbers.
@@ -0,0 +1,256 @@
1
+ # Radix Integer
2
+
3
+ Radix provides an Integer class for working with integers in various bases.
4
+
5
+ require 'radix'
6
+
7
+ ## Initialization
8
+
9
+ Radix::Integer's initializer can accept either an Integer, String or
10
+ Array as a value and an integer base.
11
+
12
+ Give an integer value, it will automatically be converted to the base
13
+ specified.
14
+
15
+ check do |integer, base, digits|
16
+ r = Radix::Integer.new(integer, base)
17
+ r.digits.assert == digits
18
+ end
19
+
20
+ ok 8, 2, [1,0,0,0]
21
+ ok 4, 2, [1,0,0]
22
+ ok 8, 10, [8]
23
+ ok 10, 10, [1, 0]
24
+ ok 8, 16, [8]
25
+ ok 16, 16, [1, 0]
26
+
27
+ Where as a String value is taken to already be in the base given.
28
+
29
+ ok "1000", 2, [1,0,0,0]
30
+ ok "100", 2, [1,0,0]
31
+
32
+ ok "8", 10, [8]
33
+ ok "10", 10, [1, 0]
34
+ ok "8", 16, [8]
35
+ ok "10", 16, [1, 0]
36
+
37
+ And an Array is also taken to be in the base given.
38
+
39
+ ok %w[1 0 0 0], 2, [1,0,0,0]
40
+ ok %w[ 1 0 0], 2, [1,0,0]
41
+
42
+ ok %w[ 8], 10, [8]
43
+ ok %w[1 0], 10, [1, 0]
44
+ ok %w[ 8], 16, [8]
45
+ ok %w[1 0], 16, [1, 0]
46
+
47
+ Integers can also be negative, rather than positive. In each case
48
+ just prepend the value with a minus sign.
49
+
50
+ check do |integer, base, digits|
51
+ r = Radix::Integer.new(integer, base)
52
+ r.digits.assert == digits
53
+ r.assert.negative?
54
+ end
55
+
56
+ ok -8, 2, ['-',1,0,0,0]
57
+ ok "-1000", 2, ['-',1,0,0,0]
58
+ ok %w[- 1 0 0 0], 2, ['-',1,0,0,0]
59
+
60
+ If a value has a digit outside of the range of the base an ArgumentError
61
+ will be raised.
62
+
63
+ expect ArgumentError do
64
+ Radix::Integer.new('9', 2)
65
+ end
66
+
67
+ Radix provides a convenience extension method to Integer, String and Array
68
+ called #b, to more easily initialize a Radix numeric object. The method simply
69
+ passes the receiver on to `Radix::Integer#new`.
70
+
71
+ check do |integer, base, digits|
72
+ r = integer.b(base)
73
+ r.assert.is_a?(Radix::Integer)
74
+ r.digits.assert == digits
75
+ end
76
+
77
+ ok 8, 2, [1,0,0,0]
78
+ ok 4, 2, [1,0,0]
79
+
80
+ ok "1000", 2, [1,0,0,0]
81
+ ok "100", 2, [1,0,0]
82
+
83
+ ok %w"1 0 0 0", 2, [1,0,0,0]
84
+ ok %w"1 0 0", 2, [1,0,0]
85
+
86
+ ## Conversion
87
+
88
+ Radix integers can ve converted to other bases with the #convert method.
89
+
90
+ b = "1000".b(2)
91
+ d = b.convert(10)
92
+ d.digits.assert == [8]
93
+
94
+ We can convert a Radix::Integer to a regular base-10 Integer with the #to_i
95
+ method.
96
+
97
+ b = "1000".b(2)
98
+ d = b.to_i
99
+ d.assert == 8
100
+
101
+ ## Equality
102
+
103
+ Radix extend the Integer, String and Array classes with the #b method
104
+ which simplifies the creation of Radix::Integer instances. The following
105
+ return the equivalent instance of Radix::Integer.
106
+
107
+ a = 8.b(2)
108
+ b = "1000".b(2)
109
+ c = [1, 0, 0, 0].b(2)
110
+
111
+ a.assert == b
112
+ b.assert == c
113
+ c.assert == a
114
+
115
+ a.assert == 8
116
+ b.assert == 8
117
+ c.assert == 8
118
+
119
+ More stringent equality can be had from #eql?, in which the other integer
120
+ must be a Radix::Integer too.
121
+
122
+ a.assert.eql?(b)
123
+ a.refute.eql?(8)
124
+
125
+ ## Operations
126
+
127
+ Radix::Integer supports all the usual mathematical operators.
128
+
129
+ ### Addition
130
+
131
+ check do |a, b, x|
132
+ (a + b).assert == x
133
+ end
134
+
135
+ ok "1000".b(2), "0010".b(2), "1010".b(2)
136
+ ok "1000".b(2), "2".b(8), "1010".b(2)
137
+ ok "1000".b(2), "2".b(8), "10".b(10)
138
+
139
+ A more complex example.
140
+
141
+ x = "AZ42".b(62) + "54".b(10)
142
+ x.assert == "2518124".b(10)
143
+ x.assert == 2518124
144
+
145
+ Adding negative integers will, of course, be akin to subtraction.
146
+
147
+ ok "1000".b(2), "-0010".b(2), "110".b(2)
148
+ ok "1000".b(2), "-2".b(8), "110".b(2)
149
+ ok "1000".b(2), "-2".b(8), "6".b(10)
150
+
151
+ ok "-1000".b(2), "0010".b(2), "-110".b(2)
152
+ ok "-1000".b(2), "2".b(8), "-110".b(2)
153
+ ok "-1000".b(2), "2".b(8), "-6".b(10)
154
+
155
+ ok "-1000".b(2), "-0010".b(2), "-1010".b(2)
156
+ ok "-1000".b(2), "-2".b(8), "-1010".b(2)
157
+ ok "-1000".b(2), "-2".b(8), "-10".b(10)
158
+
159
+ ### Subtraction
160
+
161
+ check do |a, b, x|
162
+ (a - b).assert == x
163
+ end
164
+
165
+ ok "1000".b(2), "10".b(2), "0110".b(2)
166
+ ok "1000".b(2), "2".b(8), "0110".b(2)
167
+ ok "1000".b(2), "2".b(8), "6".b(8)
168
+ ok "1000".b(2), "2".b(8), "6".b(10)
169
+
170
+ A more complex example.
171
+
172
+ x = "AZ42".b(62) - "54".b(10)
173
+ x.assert == "2518016".b(10)
174
+ x.assert == 2518016
175
+
176
+ ### Multiplication
177
+
178
+ check do |a, b, x|
179
+ (a * b).assert == x
180
+ end
181
+
182
+ ok "1000".b(2), "10".b(2), "10000".b(2)
183
+ ok "1000".b(2), "2".b(8), "10000".b(2)
184
+ ok "1000".b(2), "2".b(8), "20".b(8)
185
+ ok "1000".b(2), "2".b(8), "16".b(10)
186
+
187
+ A more complex example.
188
+
189
+ x = "Z42".b(62) * "4".b(10)
190
+ x.assert == "539160".b(10)
191
+ x.assert == 539160
192
+
193
+ ### Division
194
+
195
+ check do |a, b, x|
196
+ (a / b).assert == x
197
+ end
198
+
199
+ ok "1000".b(2), "10".b(2), "100".b(2)
200
+ ok "1000".b(2), "2".b(8), "100".b(2)
201
+ ok "1000".b(2), "2".b(8), "4".b(8)
202
+ ok "1000".b(2), "2".b(8), "4".b(10)
203
+
204
+ A more complex example.
205
+
206
+ x = "AZ42".b(62) / "54".b(10)
207
+ x.assert == "46630".b(10)
208
+ x.assert == 46630
209
+
210
+ ### Power
211
+
212
+ check do |a, b, x|
213
+ (a ** b).assert == x
214
+ end
215
+
216
+ ok "1000".b(2), "10".b(2), 64
217
+
218
+ ### Modulo
219
+
220
+ check do |a, b, x|
221
+ (a % b).assert == x
222
+ end
223
+
224
+ ok "1000".b(2), "10".b(2), 0
225
+ ok "1000".b(2), "11".b(2), 2
226
+
227
+ ### Bitwise Shift
228
+
229
+ check do |a, b, x|
230
+ (a << b).assert == x
231
+ end
232
+
233
+ ok "10".b(2), "10".b(2), "1000".b(2)
234
+ ok "10".b(2), 2, "1000".b(2)
235
+ ok "10".b(2), 2, 8
236
+
237
+ ### Bitwise AND
238
+
239
+ check do |a, b, x|
240
+ (a & b).assert == x
241
+ end
242
+
243
+ ok "1010".b(2), "10".b(2), "10".b(2)
244
+ ok "1010".b(2), "2".b(8), "10".b(2)
245
+
246
+ ## Coerce
247
+
248
+ When a Radix::Integer is the operand in an operation against a regular
249
+ Ruby Integer, the calculation should still work via #coerce.
250
+
251
+ check do |a, b, x|
252
+ (a + b).assert == x
253
+ end
254
+
255
+ ok 10, "10".b(2), "12".b(10)
256
+