vipnet_parser 1.0.3 → 2.0.0
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/vipnet_parser/iplirconf.rb +16 -2
- data/lib/vipnet_parser/nodename.rb +11 -3
- data/lib/vipnet_parser/strings.rb +16 -1
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 18ba9d681a3e5cc40c4c06aaf20fa3fe75733b60
         | 
| 4 | 
            +
              data.tar.gz: 265358e6ef795a63c222842de5734456020d57f7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 67962aa3f924045d0a1a2958f1477a952f15fa6172e9456f5c4b459d06c4fbca4eda6b5b81409b29918b1901238042826dd9e0599c0bda01a0c89d276c09b52c
         | 
| 7 | 
            +
              data.tar.gz: cd51472f23c9aa2a71ef79ae7e774ace2a8d4f0840361b9fa06d728fd6d1dbf43b06be1c1fd2cf00d2e9f36d0b9b30f89fd15954e5b590b80fa225005a0123c0
         | 
| @@ -8,7 +8,14 @@ module VipnetParser | |
| 8 8 | 
             
                  @string = iplirconf_file
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            -
                 | 
| 11 | 
            +
                DEFAULT_PARSE_ARGS = { format: :hash, encoding: "koi8-r", normalize_names: false }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def parse(args = DEFAULT_PARSE_ARGS)
         | 
| 14 | 
            +
                  args = DEFAULT_PARSE_ARGS.merge(args)
         | 
| 15 | 
            +
                  format = args[:format]
         | 
| 16 | 
            +
                  encoding = args[:encoding]
         | 
| 17 | 
            +
                  normalize_names = args[:normalize_names]
         | 
| 18 | 
            +
             | 
| 12 19 | 
             
                  # change encoding to utf8 and remove comments
         | 
| 13 20 | 
             
                  string = self.string
         | 
| 14 21 | 
             
                    .force_encoding(encoding)
         | 
| @@ -35,7 +42,7 @@ module VipnetParser | |
| 35 42 |  | 
| 36 43 | 
             
                  case format
         | 
| 37 44 | 
             
                  when :hash
         | 
| 38 | 
            -
                    @hash = { _meta: { version: " | 
| 45 | 
            +
                    @hash = { _meta: { version: "3" }}
         | 
| 39 46 | 
             
                    hash_keys = {
         | 
| 40 47 | 
             
                      id: :id,
         | 
| 41 48 | 
             
                      adapter: :name,
         | 
| @@ -47,6 +54,13 @@ module VipnetParser | |
| 47 54 | 
             
                      if hash_key
         | 
| 48 55 | 
             
                        hash, current_key = _section_hash(section[:content], hash_key)
         | 
| 49 56 | 
             
                        @hash[section[:name]][current_key] = hash
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                        # normalize names
         | 
| 59 | 
            +
                        # (only available for [id] sections, which are processed with current_key == id)
         | 
| 60 | 
            +
                        name = @hash[section[:name]][current_key][:name]
         | 
| 61 | 
            +
                        if name && normalize_names
         | 
| 62 | 
            +
                          @hash[section[:name]][current_key][:name] = VipnetParser.name(name, current_key)
         | 
| 63 | 
            +
                        end
         | 
| 50 64 | 
             
                      else
         | 
| 51 65 | 
             
                        hash, _ = _section_hash(section[:content])
         | 
| 52 66 | 
             
                        @hash[section[:name]] = hash
         | 
| @@ -8,7 +8,14 @@ module VipnetParser | |
| 8 8 | 
             
                  @string = nodename_file
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            -
                 | 
| 11 | 
            +
                DEFAULT_PARSE_ARGS = { format: :hash, encoding: "cp866", normalize_names: false }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def parse(args = DEFAULT_PARSE_ARGS)
         | 
| 14 | 
            +
                  args = DEFAULT_PARSE_ARGS.merge(args)
         | 
| 15 | 
            +
                  format = args[:format]
         | 
| 16 | 
            +
                  encoding = args[:encoding]
         | 
| 17 | 
            +
                  normalize_names = args[:normalize_names]
         | 
| 18 | 
            +
             | 
| 12 19 | 
             
                  # change encoding to utf8
         | 
| 13 20 | 
             
                  string = self.string
         | 
| 14 21 | 
             
                    .force_encoding(encoding)
         | 
| @@ -16,14 +23,15 @@ module VipnetParser | |
| 16 23 |  | 
| 17 24 | 
             
                  case format
         | 
| 18 25 | 
             
                  when :hash
         | 
| 19 | 
            -
                    @hash = { _meta: { version: " | 
| 26 | 
            +
                    @hash = { _meta: { version: "3" }, id: {} }
         | 
| 20 27 |  | 
| 21 28 | 
             
                    string.split("\r\n").each do |line|
         | 
| 22 29 | 
             
                      record = _record_hash(line)
         | 
| 23 30 | 
             
                      record[:name].rstrip!
         | 
| 24 31 | 
             
                      record[:enabled] = { "1" => true, "0" => false }[record[:enabled]]
         | 
| 25 32 | 
             
                      record[:category] = { "A" => :client, "S" => :server, "G" => :group }[record[:category]]
         | 
| 26 | 
            -
                      normal_id = VipnetParser | 
| 33 | 
            +
                      normal_id = VipnetParser.id(record[:id]).first
         | 
| 34 | 
            +
                      record[:name] = VipnetParser.name(record[:name], normal_id) if normalize_names
         | 
| 27 35 | 
             
                      record.delete(:id)
         | 
| 28 36 | 
             
                      @hash[:id][normal_id] = record
         | 
| 29 37 | 
             
                    end
         | 
| @@ -35,6 +35,7 @@ module VipnetParser | |
| 35 35 | 
             
                    end
         | 
| 36 36 | 
             
                  end
         | 
| 37 37 | 
             
                end
         | 
| 38 | 
            +
             | 
| 38 39 | 
             
                if string_matches_anything
         | 
| 39 40 | 
             
                  return array.uniq.sort
         | 
| 40 41 | 
             
                else
         | 
| @@ -56,6 +57,7 @@ module VipnetParser | |
| 56 57 | 
             
                (interval_end - interval_begin + 1).times do |n|
         | 
| 57 58 | 
             
                  array.push("0x#{(interval_begin + n).to_s(16).rjust(8, '0')}")
         | 
| 58 59 | 
             
                end
         | 
| 60 | 
            +
             | 
| 59 61 | 
             
                array
         | 
| 60 62 | 
             
              end
         | 
| 61 63 |  | 
| @@ -75,8 +77,21 @@ module VipnetParser | |
| 75 77 | 
             
                  normal_id = normal_ids[0]
         | 
| 76 78 | 
             
                  return id[2..5].to_i(16).to_s(10)
         | 
| 77 79 | 
             
                end
         | 
| 80 | 
            +
             | 
| 78 81 | 
             
                false
         | 
| 79 82 | 
             
              end
         | 
| 80 83 |  | 
| 81 | 
            -
               | 
| 84 | 
            +
              MAX_NAME_SIZE = 50
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              def name(name, vid)
         | 
| 87 | 
            +
                return name unless name.size == MAX_NAME_SIZE
         | 
| 88 | 
            +
                network = network(vid)
         | 
| 89 | 
            +
                search_range = (MAX_NAME_SIZE - network.size..-1)
         | 
| 90 | 
            +
                inverted_search_range = (0..MAX_NAME_SIZE - network.size - 1)
         | 
| 91 | 
            +
                return name[inverted_search_range].strip if name[search_range] == network
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                name
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              module_function :id, :network, :name
         | 
| 82 97 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: vipnet_parser
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alexander Morozov
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-01-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 | 
            -
            description: Parses ViPNet IDs, iplir.conf and other files
         | 
| 13 | 
            +
            description: Parses ViPNet™ IDs, iplir.conf and other files
         | 
| 14 14 | 
             
            email: ntcomp12@gmail.com
         | 
| 15 15 | 
             
            executables: []
         | 
| 16 16 | 
             
            extensions: []
         | 
| @@ -41,8 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 41 41 | 
             
                  version: '0'
         | 
| 42 42 | 
             
            requirements: []
         | 
| 43 43 | 
             
            rubyforge_project: 
         | 
| 44 | 
            -
            rubygems_version: 2. | 
| 44 | 
            +
            rubygems_version: 2.5.2
         | 
| 45 45 | 
             
            signing_key: 
         | 
| 46 46 | 
             
            specification_version: 4
         | 
| 47 | 
            -
            summary: ViPNet strings parser
         | 
| 47 | 
            +
            summary: ViPNet™ strings parser
         | 
| 48 48 | 
             
            test_files: []
         |