Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ebcdic_converter.rb

Instance Method Summary collapse

Instance Method Details

#ebcdic_to_i(*options) ⇒ Object

extends the string class to convert one ebcdic representation to a number For example:

‘12C’ => 123 ‘12L’ => -123



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ebcdic_converter.rb', line 44

def ebcdic_to_i(*options)
  unless options.empty?
    @strict = options[0][:strict]
  end
  stripped_me = strip
  if stripped_me.size > 0
    last_digit = stripped_me[-1..-1]
    last_digit =~ /^\d$/ ?
      stricted(stripped_me.to_i) :
      one_char_to_ebcdic(stripped_me)
  else
    0
  end
end

#to_ebcdicObject

Converts existing number to ebcdic. For example

‘123’ => ‘12C’ ‘-123’ => ‘12L’



64
65
66
67
68
69
# File 'lib/ebcdic_converter.rb', line 64

def to_ebcdic
  new_str = self.dup
  self[0..0] == '-' ?
    new_str[1..-2] << EbcdicConverter::EBCDICNEG.invert[new_str[-1..-1]] :
    new_str[0..-2] << EbcdicConverter::EBCDICPOS.invert[new_str[-1..-1]]
end