immosquare-extensions 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/immosquare-extensions/file.rb +18 -2
 - data/lib/immosquare-extensions/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e1bac31a6c2a9a5a15dc679176b78175cfc45f206f769e1dfaf651f32c9765a4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b46910b5fa67745109a1dfe38b9150797dc8eded7f1f4abc5bee4ee91cb27d84
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7a991f9a2afa423b7fa4b97cc771b6587a686a2a60ca81ed5bafdf9fc55655433640a118e3d3491400690342450655afac09ee8032e91f21f79e2b7a39d47ffb
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 81e58a39befe80f489aa89d12589219146558684be06a864ebd3c828824fa895160cc333fa283138d125a227370d0c699fe146483c6db1b51373cf0729bffe0e
         
     | 
| 
         @@ -14,12 +14,28 @@ class File 
     | 
|
| 
       14 
14 
     | 
    
         
             
              ## The total number of lines in the normalized file.
         
     | 
| 
       15 
15 
     | 
    
         
             
              ##===========================================================================##
         
     | 
| 
       16 
16 
     | 
    
         
             
              def self.normalize_last_line(file_path)
         
     | 
| 
      
 17 
     | 
    
         
            +
                ##============================================================##
         
     | 
| 
      
 18 
     | 
    
         
            +
                ## Get the file size
         
     | 
| 
      
 19 
     | 
    
         
            +
                ##============================================================##
         
     | 
| 
      
 20 
     | 
    
         
            +
                file_size = File.size?(file_path)
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                ##============================================================##
         
     | 
| 
      
 23 
     | 
    
         
            +
                ## If the file is empty (0 bytes), there's nothing to normalize.
         
     | 
| 
      
 24 
     | 
    
         
            +
                ##============================================================##
         
     | 
| 
      
 25 
     | 
    
         
            +
                return 0 if file_size.nil? || file_size == 0
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       17 
28 
     | 
    
         
             
                end_of_line = $INPUT_RECORD_SEPARATOR || "\n"
         
     | 
| 
       18 
29 
     | 
    
         
             
                ##============================================================##
         
     | 
| 
       19 
30 
     | 
    
         
             
                ## Read all lines from the file
         
     | 
| 
       20 
31 
     | 
    
         
             
                ## https://gist.github.com/guilhermesimoes/d69e547884e556c3dc95
         
     | 
| 
      
 32 
     | 
    
         
            +
                ## Detect the encoding of the file using uchardet
         
     | 
| 
      
 33 
     | 
    
         
            +
                ## Read the content of the file with the detected encoding,
         
     | 
| 
      
 34 
     | 
    
         
            +
                ## falling back to UTF-8 if the detected encoding is empty or invalid.
         
     | 
| 
       21 
35 
     | 
    
         
             
                ##============================================================##
         
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 36 
     | 
    
         
            +
                detected_encoding = `uchardet #{file_path}`.strip
         
     | 
| 
      
 37 
     | 
    
         
            +
                encoding_to_use   = detected_encoding.empty? ? "UTF-8" : "#{detected_encoding}:UTF-8"
         
     | 
| 
      
 38 
     | 
    
         
            +
                content           = File.read(file_path, :encoding => encoding_to_use)
         
     | 
| 
       23 
39 
     | 
    
         | 
| 
       24 
40 
     | 
    
         
             
                ##===========================================================================##
         
     | 
| 
       25 
41 
     | 
    
         
             
                ## Remove all trailing empty lines at the end of the file
         
     | 
| 
         @@ -34,7 +50,7 @@ class File 
     | 
|
| 
       34 
50 
     | 
    
         
             
                ##===========================================================================##
         
     | 
| 
       35 
51 
     | 
    
         
             
                ## Write the modified lines back to the file
         
     | 
| 
       36 
52 
     | 
    
         
             
                ##===========================================================================##
         
     | 
| 
       37 
     | 
    
         
            -
                File.write(file_path, content)
         
     | 
| 
      
 53 
     | 
    
         
            +
                File.write(file_path, content, :encoding => encoding_to_use)
         
     | 
| 
       38 
54 
     | 
    
         | 
| 
       39 
55 
     | 
    
         
             
                ##===========================================================================##
         
     | 
| 
       40 
56 
     | 
    
         
             
                ## Return the total number of lines in the modified file
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: immosquare-extensions
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.14
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - IMMO SQUARE
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-02- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-02-06 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: unicode_utils
         
     |