ebcdic_converter 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ebcdic_converter}
8
- s.version = "1.1.2"
8
+ s.version = "1.1.3"
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-07-14}
12
+ s.date = %q{2010-07-15}
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 = [
@@ -34,12 +34,15 @@ module EbcdicConverter
34
34
  end
35
35
 
36
36
  class String
37
- def ebcdic_to_i
37
+ def ebcdic_to_i(*options)
38
+ unless options.empty?
39
+ @strict = options[0][:strict]
40
+ end
38
41
  stripped_me = strip
39
42
  if stripped_me.size > 0
40
43
  last_digit = stripped_me[-1..-1]
41
44
  last_digit =~ /^\d$/ ?
42
- stripped_me.to_i :
45
+ stricted(stripped_me.to_i) :
43
46
  to_ebcdic(stripped_me)
44
47
  else
45
48
  0
@@ -48,6 +51,14 @@ class String
48
51
 
49
52
  private
50
53
 
54
+ def stricted(integer)
55
+ if @strict
56
+ raise "Invalid EBCDIC Numberin #{self.to_s}"
57
+ else
58
+ integer
59
+ end
60
+ end
61
+
51
62
  def to_ebcdic(stripped_me)
52
63
  last_digit = stripped_me[-1..-1]
53
64
  EbcdicConverter::EBCDICPOS.keys.include?(last_digit) ?
@@ -13,8 +13,13 @@ describe "EbcdicConverter" do
13
13
  "12K".ebcdic_to_i.should == -122
14
14
  end
15
15
  it "converts last digit to 0 if it's a } OR {" do
16
- "00012}".ebcdic_to_i.should == 120
17
- "00012{".ebcdic_to_i.should == -120
16
+ "00012{".ebcdic_to_i.should == 120
17
+ "00012}".ebcdic_to_i.should == -120
18
+ end
19
+ it "raises an error when we set :strict => true" do
20
+ lambda {
21
+ "000121".ebcdic_to_i(:strict => true)
22
+ }.should raise_error
18
23
  end
19
24
  end
20
25
  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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
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-07-14 00:00:00 -04:00
18
+ date: 2010-07-15 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency