dcidev_utility 0.0.4 → 0.0.5
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/README.md +7 -0
- data/lib/dcidev_utility.rb +33 -14
- 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: '095a6cdee9fb7558cd1beac901c1e2a642f1cf005476d1acf0c9812785c3f11a'
         | 
| 4 | 
            +
              data.tar.gz: 6b2c77e34252fadf974543f6b2b5410e916089a77f8ab45ba19b5139d0f705e7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d7e3f0669cf57e6c4cda4bad185516d9c992e79d3a217b5397309ccb8f7c572635aefeafe4a5748ce0f9f3e2783e39f03b703174c0b338f133911dd773c12b91
         | 
| 7 | 
            +
              data.tar.gz: e187a91b8d3e9d5909b3f947e10d5db7eaa22795c8172abb7ec09222b571d220dd6c2c4d7446dd6780d2c06304cd395ee3fab1516424c396a7bb766890dcf525
         | 
    
        data/README.md
    CHANGED
    
    | @@ -52,4 +52,11 @@ DcidevUtility.response_simplifier(response) | |
| 52 52 |  | 
| 53 53 | 
             
            # takeout base64 string from json hash
         | 
| 54 54 | 
             
            DcidevUtility.json_simplifier(json)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            # get difference in seconds
         | 
| 57 | 
            +
            DcidevUtility.seconds_diff(start, finish)
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            # get difference in years
         | 
| 60 | 
            +
            DcidevUtility.years_between(date_from, date_to)
         | 
| 61 | 
            +
             | 
| 55 62 | 
             
            ```
         | 
    
        data/lib/dcidev_utility.rb
    CHANGED
    
    | @@ -17,18 +17,14 @@ module DcidevUtility | |
| 17 17 | 
             
                    end
         | 
| 18 18 |  | 
| 19 19 | 
             
                    def download_to_file(url)
         | 
| 20 | 
            -
                         | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
                             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
                                file.rewind
         | 
| 29 | 
            -
                            end
         | 
| 30 | 
            -
                        rescue => e
         | 
| 31 | 
            -
                            return nil
         | 
| 20 | 
            +
                        uri = URI::parse(url)
         | 
| 21 | 
            +
                        extension = File.extname(uri.path)
         | 
| 22 | 
            +
                        stream = URI::open(url, "rb")
         | 
| 23 | 
            +
                        Tempfile.new([File.basename(uri.path), extension]).tap do |file|
         | 
| 24 | 
            +
                            file.binmode
         | 
| 25 | 
            +
                            IO.copy_stream(stream, file)
         | 
| 26 | 
            +
                            stream.close
         | 
| 27 | 
            +
                            file.rewind
         | 
| 32 28 | 
             
                        end
         | 
| 33 29 | 
             
                    end
         | 
| 34 30 |  | 
| @@ -166,9 +162,24 @@ module DcidevUtility | |
| 166 162 | 
             
                        base64.split(";").first.split(":").last
         | 
| 167 163 | 
             
                    end
         | 
| 168 164 |  | 
| 169 | 
            -
                    def string_masking(string, length = 9)
         | 
| 165 | 
            +
                    def string_masking(string, length = 9, replace_charcter: 'x')
         | 
| 166 | 
            +
                        return "" if string.nil?
         | 
| 167 | 
            +
                        return string.sub(string[0...length], replace_charcter * length)
         | 
| 168 | 
            +
                    end
         | 
| 169 | 
            +
             | 
| 170 | 
            +
                    def random_string_masking(string, length = 0, replace_character: '*')
         | 
| 170 171 | 
             
                        return "" if string.nil?
         | 
| 171 | 
            -
                         | 
| 172 | 
            +
                        length.clamp(0, string.length).times do
         | 
| 173 | 
            +
                            random_pos = nil
         | 
| 174 | 
            +
                            loop do
         | 
| 175 | 
            +
                                random_pos = rand(0...string.length)
         | 
| 176 | 
            +
                                if string[random_pos] != replace_character
         | 
| 177 | 
            +
                                    break
         | 
| 178 | 
            +
                                end
         | 
| 179 | 
            +
                            end
         | 
| 180 | 
            +
                            string[random_pos] = replace_character
         | 
| 181 | 
            +
                        end
         | 
| 182 | 
            +
                        return string
         | 
| 172 183 | 
             
                    end
         | 
| 173 184 |  | 
| 174 185 | 
             
                    def response_simplifier(response)
         | 
| @@ -225,5 +236,13 @@ module DcidevUtility | |
| 225 236 | 
             
                        end
         | 
| 226 237 | 
             
                        return simplified
         | 
| 227 238 | 
             
                    end
         | 
| 239 | 
            +
             | 
| 240 | 
            +
                    def seconds_diff(start, finish)
         | 
| 241 | 
            +
                        (start - finish).seconds.round
         | 
| 242 | 
            +
                    end
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                    def years_between(date_from, date_to)
         | 
| 245 | 
            +
                        (date_from.year - date_to.year).abs
         | 
| 246 | 
            +
                    end
         | 
| 228 247 | 
             
                end
         | 
| 229 248 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dcidev_utility
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Punto Damar P
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022- | 
| 11 | 
            +
            date: 2022-09-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: Testing phase
         | 
| 14 14 | 
             
            email:
         |