class CnabRb::Format::PictureFormats::Float
Public Class Methods
new(length_left, length_right)
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 3 def initialize(length_left, length_right) @length_right = length_right @format_left = CnabRb::Format::PictureFormats::Integer.new(length_left) end
Public Instance Methods
decode(value)
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 22 def decode(value) value.to_f / 10.pow(@length_right) end
encode(value)
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 8 def encode(value) left_value = get_left_value(value) right_value = get_right_value(value) left_value + right_value end
get_left_value(value)
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 14 def get_left_value(value) @format_left.encode(value.to_s.split('.')[0]) end
get_right_value(value)
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 18 def get_right_value(value) value.to_f.round(@length_right).to_s.split('.')[1].ljust(@length_right, '0') end
length()
click to toggle source
# File lib/cnab_rb/format/picture_formats/float.rb, line 26 def length @format_left.length + @length_right end