ebcdic_converter 1.1.3 → 1.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.
- data/VERSION +1 -1
- data/ebcdic_converter.gemspec +2 -2
- data/lib/ebcdic_converter.rb +22 -2
- data/spec/ebcdic_converter_spec.rb +8 -0
- metadata +5 -5
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.2.0
|
data/ebcdic_converter.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{ebcdic_converter}
|
|
8
|
-
s.version = "1.
|
|
8
|
+
s.version = "1.2.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Bernie Telles"]
|
|
12
|
-
s.date = %q{2010-
|
|
12
|
+
s.date = %q{2010-08-17}
|
|
13
13
|
s.description = %q{Adds a method (ebcdic_to_i) to String that converts it from ebcdic to integer}
|
|
14
14
|
s.email = %q{btelles@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/ebcdic_converter.rb
CHANGED
|
@@ -34,6 +34,13 @@ module EbcdicConverter
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
class String
|
|
37
|
+
# extends the string class to convert
|
|
38
|
+
# one ebcdic representation to a number
|
|
39
|
+
# For example:
|
|
40
|
+
#
|
|
41
|
+
# '12C' => 123
|
|
42
|
+
# '12L' => -123
|
|
43
|
+
#
|
|
37
44
|
def ebcdic_to_i(*options)
|
|
38
45
|
unless options.empty?
|
|
39
46
|
@strict = options[0][:strict]
|
|
@@ -43,12 +50,25 @@ class String
|
|
|
43
50
|
last_digit = stripped_me[-1..-1]
|
|
44
51
|
last_digit =~ /^\d$/ ?
|
|
45
52
|
stricted(stripped_me.to_i) :
|
|
46
|
-
|
|
53
|
+
one_char_to_ebcdic(stripped_me)
|
|
47
54
|
else
|
|
48
55
|
0
|
|
49
56
|
end
|
|
50
57
|
end
|
|
51
58
|
|
|
59
|
+
# Converts existing number to ebcdic.
|
|
60
|
+
# For example
|
|
61
|
+
#
|
|
62
|
+
# '123' => '12C'
|
|
63
|
+
# '-123' => '12L'
|
|
64
|
+
def to_ebcdic
|
|
65
|
+
new_str = self.dup
|
|
66
|
+
self[0..0] == '-' ?
|
|
67
|
+
new_str[1..-2] << EbcdicConverter::EBCDICNEG.invert[new_str[-1..-1]] :
|
|
68
|
+
new_str[0..-2] << EbcdicConverter::EBCDICPOS.invert[new_str[-1..-1]]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
52
72
|
private
|
|
53
73
|
|
|
54
74
|
def stricted(integer)
|
|
@@ -59,7 +79,7 @@ class String
|
|
|
59
79
|
end
|
|
60
80
|
end
|
|
61
81
|
|
|
62
|
-
def
|
|
82
|
+
def one_char_to_ebcdic(stripped_me)
|
|
63
83
|
last_digit = stripped_me[-1..-1]
|
|
64
84
|
EbcdicConverter::EBCDICPOS.keys.include?(last_digit) ?
|
|
65
85
|
unsigned_ebcdic(stripped_me) :
|
|
@@ -22,4 +22,12 @@ describe "EbcdicConverter" do
|
|
|
22
22
|
}.should raise_error
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
+
describe "to_ebcdic" do
|
|
26
|
+
it 'converts a positive string' do
|
|
27
|
+
'123'.to_ebcdic.should == '12C'
|
|
28
|
+
end
|
|
29
|
+
it 'converts a negative string' do
|
|
30
|
+
'-123'.to_ebcdic.should == '12L'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
25
33
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ebcdic_converter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 1.
|
|
8
|
+
- 2
|
|
9
|
+
- 0
|
|
10
|
+
version: 1.2.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Bernie Telles
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-08-17 00:00:00 -04:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|