Class: BrDanfe::DanfeLib::NfeLib::Helper
- Inherits:
-
Object
- Object
- BrDanfe::DanfeLib::NfeLib::Helper
- Defined in:
- lib/br_danfe/danfe_lib/nfe_lib/helper.rb
Class Method Summary collapse
- .address_is_too_big(pdf, address) ⇒ Object
- .format_date(xml_datetime) ⇒ Object
- .format_time(xml_datetime) ⇒ Object
- .generate_address(xml, path) ⇒ Object
- .invert(y) ⇒ Object
- .mensure_text(pdf, text) ⇒ Object
Class Method Details
.address_is_too_big(pdf, address) ⇒ Object
37 38 39 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 37 def self.address_is_too_big(pdf, address) Helper.mensure_text(pdf, address) > Dest::MAXIMUM_SIZE_FOR_STREET end |
.format_date(xml_datetime) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 9 def self.format_date(xml_datetime) formated = '' unless xml_datetime.empty? date = DateTime.strptime(xml_datetime, '%Y-%m-%d') formated = date.strftime('%d/%m/%Y') end formated end |
.format_time(xml_datetime) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 20 def self.format_time(xml_datetime) formated = '' if xml_datetime.length == 8 formated = xml_datetime elsif xml_datetime.length > 8 date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S %Z').to_time formated = date.strftime('%H:%M:%S') end formated end |
.generate_address(xml, path) ⇒ Object
41 42 43 44 45 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 41 def self.generate_address(xml, path) address_complement = " - #{xml_text(xml, "#{path}/xCpl")}" if xml_text(xml, "#{path}/xCpl").present? address_number = " #{xml_text(xml, "#{path}/nro")}" if xml_text(xml, "#{path}/nro").present? "#{xml_text(xml, "#{path}/xLgr")}#{address_number}#{address_complement}" end |
.invert(y) ⇒ Object
5 6 7 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 5 def self.invert(y) 29.7.cm - y end |
.mensure_text(pdf, text) ⇒ Object
33 34 35 |
# File 'lib/br_danfe/danfe_lib/nfe_lib/helper.rb', line 33 def self.mensure_text(pdf, text) pdf.width_of(text) end |