Skip to content

Commit

Permalink
raises descriptive exception if bad iconv version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Foley committed Apr 30, 2012
1 parent 0944a03 commit 5264d36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/pixxxer/field_depixxxitter.rb
Expand Up @@ -70,5 +70,7 @@ def coerce_field(field)
class EbcdicStringFieldDepixxxitter < FieldDepixxxitter
def coerce_field(field)
Iconv.iconv('ASCII', 'EBCDIC-US', field)
rescue Iconv::InvalidEncoding => e
raise e, 'EBCDIC-US encoding unavailable on your iconv version: %s' % e
end
end
10 changes: 6 additions & 4 deletions lib/pixxxer/field_pixxxitter.rb
@@ -1,4 +1,5 @@
require 'iconv'

class FieldPixxxitter
def initialize(field)
@field = field
Expand Down Expand Up @@ -44,7 +45,7 @@ def inject_field(record, field)

class NumberFieldPixxxitter < FieldPixxxitter
def is_valid?(field)
true if Float(field) rescue false
!!Float(field) rescue false
end
def shorten_field(field)
if @field.width
Expand All @@ -64,7 +65,7 @@ def pad_field(field)

class IntegerFieldPixxxitter < NumberFieldPixxxitter
def is_valid?(field)
true if Integer(field) rescue false
!!Integer(field) rescue false
end
def coerce_field(field)
is_valid?(field) ? field : ''
Expand Down Expand Up @@ -118,8 +119,9 @@ def coerce_field(field)

class EbcdicStringFieldPixxxitter < FieldPixxxitter
def coerce_field(field)
@@ea_iconv ||= Iconv.new('EBCDIC-US', 'ASCII')
@@ea_iconv.iconv(field.to_s)
Iconv.iconv('EBCDIC-US', 'ASCII', field.to_s)
rescue Iconv::InvalidEncoding => e
raise e, 'EBCDIC-US encoding unavailable on your iconv version: %s' % e
end
def pad_field(field)
if @field.width
Expand Down

0 comments on commit 5264d36

Please sign in to comment.