module Kinabo::Utils

Public Instance Methods

fill_sequencial(lines) click to toggle source
# File lib/kinabo/utils.rb, line 35
def fill_sequencial(lines)
  lines.map.with_index(1) { |line, index| line + justify_number(index, 6) }.join("\r\n") + "\r\n"
end
justify_number(number, length) click to toggle source
# File lib/kinabo/utils.rb, line 9
def justify_number(number, length)
  number.to_s.rjust(length, '0')
end
justify_string(string, length) click to toggle source
# File lib/kinabo/utils.rb, line 5
def justify_string(string, length)
  I18n.transliterate(string.to_s).truncate(length, omission: '').ljust(length, ' ')
end
justify_value(value, length, decimal_places = 2) click to toggle source
# File lib/kinabo/utils.rb, line 13
def justify_value(value, length, decimal_places = 2)
  ("%.#{decimal_places}f" % (value || 0)).gsub(/[.,]/, '').rjust(length, '0')
end
parse_date(string) click to toggle source
# File lib/kinabo/utils.rb, line 21
def parse_date(string)
  return nil if string.to_i.zero?

  DateTime.strptime(string, "%d%m%y")
end
parse_decimal(string) click to toggle source
# File lib/kinabo/utils.rb, line 17
def parse_decimal(string)
  string.to_f / 100.0
end
parse_number(string) click to toggle source
# File lib/kinabo/utils.rb, line 31
def parse_number(string)
  string.to_i
end
parse_string(string) click to toggle source
# File lib/kinabo/utils.rb, line 27
def parse_string(string)
  string.strip
end