Module: Sped2DB::Utils
Instance Method Summary collapse
- #count_lines(file_path) ⇒ Object
- #date_string?(str) ⇒ Boolean
- #get_first_line(file_path) ⇒ Object
- #get_first_line_fields(file_path) ⇒ Object
- #get_layout(file_path) ⇒ Object
- #sped_file?(file_path) ⇒ Boolean
Instance Method Details
#count_lines(file_path) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/sped2db/utils.rb', line 14 def count_lines(file_path) # linux `wc -l "#{file_path}"`.strip.split(' ')[0].to_i rescue # windows `find /v /c "" "#{file_path}"`.strip.split(' ').last.to_i end |
#date_string?(str) ⇒ Boolean
33 34 35 |
# File 'lib/sped2db/utils.rb', line 33 def date_string?(str) str =~ /^\d{8}$/ end |
#get_first_line(file_path) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/sped2db/utils.rb', line 3 def get_first_line(file_path) file = File.open(file_path, 'r:CP850:UTF-8') file.readline ensure file.close unless file.nil? end |
#get_first_line_fields(file_path) ⇒ Object
10 11 12 |
# File 'lib/sped2db/utils.rb', line 10 def get_first_line_fields(file_path) get_first_line(file_path).split('|', -1) end |
#get_layout(file_path) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/sped2db/utils.rb', line 26 def get_layout(file_path) fields = get_first_line_fields(file_path) type = date_string?(fields[4]) ? :fiscal : :contrib version = fields[2] Layout.new type, version end |
#sped_file?(file_path) ⇒ Boolean
22 23 24 |
# File 'lib/sped2db/utils.rb', line 22 def sped_file?(file_path) File.file?(file_path) && get_first_line_fields(file_path)[1] == '0000' end |