Module: Kinabo::Utils
- Included in:
- Bradesco::Remessa::Builder, Bradesco::Remessa::Header, Bradesco::Remessa::Mensagem, Bradesco::Remessa::Pagador, Bradesco::Remessa::Trailler, Bradesco::Remessa::Transacao, Bradesco::Retorno, Fromtis::Remessa::Builder, Fromtis::Remessa::Header, Fromtis::Remessa::Trailler, Fromtis::Remessa::Transacao
- Defined in:
- lib/kinabo/utils.rb
Instance Method Summary collapse
- #fill_sequencial(lines) ⇒ Object
- #justify_number(number, length) ⇒ Object
- #justify_string(string, length) ⇒ Object
- #justify_value(value, length, decimal_places = 2) ⇒ Object
- #parse_date(string) ⇒ Object
- #parse_decimal(string) ⇒ Object
- #parse_number(string) ⇒ Object
- #parse_string(string) ⇒ Object
Instance Method Details
#fill_sequencial(lines) ⇒ Object
35 36 37 |
# 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) ⇒ Object
9 10 11 |
# File 'lib/kinabo/utils.rb', line 9 def justify_number(number, length) number.to_s.rjust(length, '0') end |
#justify_string(string, length) ⇒ Object
5 6 7 |
# 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) ⇒ Object
13 14 15 |
# 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) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/kinabo/utils.rb', line 17 def parse_decimal(string) string.to_f / 100.0 end |
#parse_number(string) ⇒ Object
31 32 33 |
# File 'lib/kinabo/utils.rb', line 31 def parse_number(string) string.to_i end |
#parse_string(string) ⇒ Object
27 28 29 |
# File 'lib/kinabo/utils.rb', line 27 def parse_string(string) string.strip end |