zold-score 0.4.4 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fea20008b46e776779c40cc80438e7a95446cd3348ed819a447c2dfe9896b2f8
4
- data.tar.gz: e077d65ccd21ffc3a331c04d45eed5e18f4af4b11cdec0c26b4ed9b27c6141bf
3
+ metadata.gz: 9ca76fd64c3274215258b3b3e8f715cc841009a0d799c9e4092c78b63558534e
4
+ data.tar.gz: 17037451897d26ee9788fa797323778d0172f0fdb4338438b64b8d64fa40fa8a
5
5
  SHA512:
6
- metadata.gz: beebaa5ce22becb6404f983d4b1214c64dc227da9a6868715c46e5f36c81fc8334c334c5996b5ecec1dc89d63ff257b6300ef1835b8ae5e0fd2f1ce6b2ad4a9e
7
- data.tar.gz: a1ee92aee0494c7c6dd74f423ac83d3bc9d5a220340d4340e45bb09c142ef1d948c658a037c81df79eebbd0a156d901276478480e7a2f85a80fe9f183f7cc23c
6
+ metadata.gz: 1b91291084be1cc34920ac013e427ee2347e327c7c8dd0c1999bbc8987f68807f47bf15d2d5eadf7c956e258d6e573beb02a1afbf7c13a672e9388033c559c36
7
+ data.tar.gz: a9103c4e4f2530fbd6a0a98baea144a28b02469e17d0e093a0018bc1d764aaa356340e0f80d2bc27a024dda1ff91b1f792ffa87fa287cb595db276190a09fca0
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
- TargetRubyVersion: 2.3.3
3
+ TargetRubyVersion: 2.5
4
4
 
5
5
  Layout/EmptyLineAfterGuardClause:
6
6
  Enabled: false
data/.simplecov CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -21,4 +21,5 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  source 'https://rubygems.org'
24
+ ruby '2.6.0'
24
25
  gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2018 Yegor Bugayenko
3
+ Copyright (c) 2018-2019 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -68,7 +68,7 @@ RuboCop::RakeTask.new(:rubocop) do |task|
68
68
  end
69
69
 
70
70
  task :copyright do
71
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
71
+ sh "grep -q -r '2018-#{Date.today.strftime('%Y')}' \
72
72
  --include '*.rb' \
73
73
  --include '*.txt' \
74
74
  --include 'Rakefile' \
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2018 Yegor Bugayenko
1
+ // Copyright (c) 2018-2019 Yegor Bugayenko
2
2
  //
3
3
  // Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  // of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/score.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -36,11 +36,14 @@ require 'time'
36
36
  # {White Paper}[https://papers.zold.io/wp.pdf].
37
37
  #
38
38
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
39
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
39
+ # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
40
40
  # License:: MIT
41
41
  module Zold
42
42
  # Score
43
43
  class Score
44
+ # When can't parse
45
+ class CantParse < StandardError; end
46
+
44
47
  # Default strength for the entire system, in production mode. The larger
45
48
  # the number, the more difficult it is to find the next score for
46
49
  # a node. If the number if too small, the values of the score will be
@@ -63,7 +66,7 @@ module Zold
63
66
  end
64
67
  @time = time
65
68
  raise 'Host can\'t be nil' if host.nil?
66
- unless host =~ /^[0-9a-z\.\-]+$/
69
+ unless /^[0-9a-z\.\-]+$/.match?(host)
67
70
  raise "Host \"#{host}\" is in a wrong format"
68
71
  end
69
72
  @host = host
@@ -79,7 +82,7 @@ module Zold
79
82
  end
80
83
  @port = port
81
84
  raise 'Invoice can\'t be nil' if invoice.nil?
82
- unless invoice =~ /^[a-zA-Z0-9]{8,32}@[a-f0-9]{16}$/
85
+ unless /^[a-zA-Z0-9]{8,32}@[a-f0-9]{16}$/.match?(invoice)
83
86
  raise "Invoice \"#{invoice}\" is wrong"
84
87
  end
85
88
  @invoice = invoice
@@ -106,7 +109,7 @@ module Zold
106
109
 
107
110
  # Parses it back from the JSON.
108
111
  def self.parse_json(json)
109
- raise 'JSON can\'t be nil' if json.nil?
112
+ raise CantParse, 'JSON can\'t be nil' if json.nil?
110
113
  Score.new(
111
114
  time: Time.parse(json['time']),
112
115
  host: json['host'],
@@ -115,6 +118,8 @@ module Zold
115
118
  suffixes: json['suffixes'],
116
119
  strength: json['strength']
117
120
  )
121
+ rescue StandardError => e
122
+ raise CantParse, "#{e.message} in \"#{json}\""
118
123
  end
119
124
 
120
125
  # Compare with another Score, by text.
@@ -160,7 +165,7 @@ module Zold
160
165
  def self.parse(text)
161
166
  raise 'Can\'t parse nil' if text.nil?
162
167
  parts = text.split(' ', 7)
163
- raise "Invalid score, not enough parts in \"#{text}\"" if parts.length < 6
168
+ raise 'Invalid score, not enough parts' if parts.length < 6
164
169
  Score.new(
165
170
  time: Time.at(parts[1].hex),
166
171
  host: parts[2],
@@ -169,6 +174,8 @@ module Zold
169
174
  suffixes: parts[6] ? parts[6].split(' ') : [],
170
175
  strength: parts[0].to_i
171
176
  )
177
+ rescue StandardError => e
178
+ raise CantParse, "#{e.message} in \"#{text}\""
172
179
  end
173
180
 
174
181
  # Returns its crypto hash. Read the White Paper for more information.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -29,7 +29,7 @@ require_relative '../../lib/zold/score'
29
29
 
30
30
  # Score test.
31
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
32
+ # Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko
33
33
  # License:: MIT
34
34
  class TestScore < Minitest::Test
35
35
  include Minitest::Hooks
@@ -108,10 +108,11 @@ class TestScore < Minitest::Test
108
108
  end
109
109
 
110
110
  def test_parses_broken_text
111
- ex = assert_raises do
112
- Zold::Score.parse('some garbage')
111
+ text = 'some garbage to parse, which can\'t be parsed'
112
+ ex = assert_raises(Zold::Score::CantParse) do
113
+ Zold::Score.parse(text)
113
114
  end
114
- assert(ex.message.include?('Invalid score'), ex)
115
+ assert(ex.message.include?(text), ex)
115
116
  end
116
117
 
117
118
  def test_prints_and_parses_zero_score
data/zold-score.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2019 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -27,9 +27,9 @@ Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0')
28
28
  end
29
29
  s.rubygems_version = '2.2'
30
- s.required_ruby_version = '>=2.3'
30
+ s.required_ruby_version = '>=2.5'
31
31
  s.name = 'zold-score'
32
- s.version = '0.4.4'
32
+ s.version = '0.4.5'
33
33
  s.license = 'MIT'
34
34
  s.summary = 'Zold score'
35
35
  s.description = 'Score calculating Ruby Gem for Zold'
@@ -48,6 +48,6 @@ Gem::Specification.new do |s|
48
48
  s.add_development_dependency 'rake-compiler', '1.0.4'
49
49
  s.add_development_dependency 'rdoc', '4.3.0'
50
50
  s.add_development_dependency 'rspec-rails', '3.8.1'
51
- s.add_development_dependency 'rubocop', '0.60.0'
52
- s.add_development_dependency 'rubocop-rspec', '1.30.0'
51
+ s.add_development_dependency 'rubocop', '0.62.0'
52
+ s.add_development_dependency 'rubocop-rspec', '1.31.0'
53
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold-score
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-16 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.60.0
103
+ version: 0.62.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.60.0
110
+ version: 0.62.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.30.0
117
+ version: 1.31.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.30.0
124
+ version: 1.31.0
125
125
  description: Score calculating Ruby Gem for Zold
126
126
  email: yegor256@gmail.com
127
127
  executables: []
@@ -162,15 +162,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - ">="
164
164
  - !ruby/object:Gem::Version
165
- version: '2.3'
165
+ version: '2.5'
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - ">="
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.7.6
172
+ rubygems_version: 3.0.1
174
173
  signing_key:
175
174
  specification_version: 2
176
175
  summary: Zold score