zold-score 0.4.2 → 0.4.3

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: 7824cd0db572815711d7dc77b9f820543a6f006c5476af408a78a027d00e8a77
4
- data.tar.gz: 1e5ce652f5365135fb299d3e432e7e09fa485e822673bacbadf53418014d2192
3
+ metadata.gz: f144b35f41f572b478b56aa45dfb771f6df83f9ffbfbe725287a39dd51eb7329
4
+ data.tar.gz: 8de2e35edc58105204a30479352af5283178b69b006e849b581c7492ac65197c
5
5
  SHA512:
6
- metadata.gz: cb927d57fa49f8805563a8664b501b82fd7b2a91a0dd6e43c801d005913b6f95b5a283e4a06d758d7cd7cfaf3e7d0e8413ec7b10781897490b926ee7436b2de1
7
- data.tar.gz: 34ec30b7f91f1f61ff106aa4a9e3d266092934571a177d6548329ae5f5c6785f7978567d98f355205d2667e406ec0aa06eec9d8f74965ff96c785cee4061291d
6
+ metadata.gz: 157659238d2e181462a65694ae60801ac49fae88e6656e709b521a6f4df172a33afbdbc759e1a81ac81ee77928cf3d552331c0fced3481d9e9d3d06fb1407f7a
7
+ data.tar.gz: 202d378faeba0c50d0d357436e3bf844c0770c12173d47a32b331369f835298d79cc759ca5c9f20938ab7929a96678ee42d0e7f570656e80268069740be5c079
data/.rubocop.yml CHANGED
@@ -6,8 +6,6 @@ Layout/EmptyLineAfterGuardClause:
6
6
  Enabled: false
7
7
  Layout/EndOfLine:
8
8
  EnforcedStyle: lf
9
- Metrics/LineLength:
10
- Max: 120
11
9
  Metrics/AbcSize:
12
10
  Max: 25
13
11
  Metrics/BlockLength:
data/lib/zold/score.rb CHANGED
@@ -63,18 +63,26 @@ module Zold
63
63
  end
64
64
 
65
65
  # The default no-value score.
66
- ZERO = Score.new(time: Time.now, host: 'localhost', invoice: 'NOPREFIX@ffffffffffffffff')
66
+ ZERO = Score.new(
67
+ time: Time.now, host: 'localhost',
68
+ invoice: 'NOPREFIX@ffffffffffffffff'
69
+ )
67
70
 
68
71
  # Parses it back from the JSON.
69
72
  def self.parse_json(json)
70
- raise "Time in JSON is broken: #{json}" unless json['time'] =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
73
+ unless json['time'] =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
74
+ raise "Time in JSON is broken: #{json}"
75
+ end
71
76
  raise "Host is wrong: #{json}" unless json['host'] =~ /^[0-9a-z\.\-]+$/
72
77
  raise "Port is wrong: #{json}" unless json['port'].is_a?(Integer)
73
- raise "Invoice is wrong: #{json}" unless json['invoice'] =~ /^[a-zA-Z0-9]{8,32}@[a-f0-9]{16}$/
78
+ unless json['invoice'] =~ /^[a-zA-Z0-9]{8,32}@[a-f0-9]{16}$/
79
+ raise "Invoice is wrong: #{json}"
80
+ end
74
81
  raise "Suffixes not array: #{json}" unless json['suffixes'].is_a?(Array)
75
82
  Score.new(
76
83
  time: Time.parse(json['time']), host: json['host'],
77
- port: json['port'], invoice: json['invoice'], suffixes: json['suffixes'],
84
+ port: json['port'], invoice: json['invoice'],
85
+ suffixes: json['suffixes'],
78
86
  strength: json['strength']
79
87
  )
80
88
  end
@@ -97,7 +105,7 @@ module Zold
97
105
  # Parses it back from the text generated by <tt>to_s</tt>.
98
106
  def self.parse(text)
99
107
  parts = text.split(' ', 7)
100
- raise "Invalid score, not enough parts in \"#{text}\"" if parts.length < 7
108
+ raise "Invalid score, not enough parts in \"#{text}\"" if parts.length < 6
101
109
  Score.new(
102
110
  time: Time.at(parts[1].hex),
103
111
  host: parts[2],
@@ -87,7 +87,8 @@ class TestScore < Minitest::Test
87
87
  time = Time.now
88
88
  score = Zold::Score.parse(
89
89
  Zold::Score.new(
90
- time: time, host: 'localhost', port: 999, invoice: 'NOPREFIX@ffffffffffffffff',
90
+ time: time, host: 'localhost', port: 999,
91
+ invoice: 'NOPREFIX@ffffffffffffffff',
91
92
  strength: 1
92
93
  ).next.next.to_s
93
94
  )
@@ -106,13 +107,14 @@ class TestScore < Minitest::Test
106
107
 
107
108
  def test_prints_and_parses_zero_score
108
109
  time = Time.now
109
- score = Zold::Score.parse(
110
- Zold::Score.new(
111
- time: time, host: '192.168.0.1', port: 1, invoice: 'NOPREFIX@ffffffffffffffff', suffixes: []
112
- ).to_s
110
+ before = Zold::Score.new(
111
+ time: time, host: '192.168.0.1', port: 1,
112
+ invoice: 'NOPREFIX@ffffffffffffffff', suffixes: []
113
113
  )
114
- assert_equal(0, score.value)
115
- assert(!score.expired?)
114
+ text = before.to_s.strip
115
+ after = Zold::Score.parse(text)
116
+ assert_equal(before.value, after.value)
117
+ assert(!after.expired?)
116
118
  end
117
119
 
118
120
  def test_finds_next_score
@@ -154,16 +156,25 @@ class TestScore < Minitest::Test
154
156
  time: Time.parse('2018-06-27T06:22:41Z'), host: 'b2.zold.io', port: 4096,
155
157
  invoice: 'THdonv1E@abcdabcdabcdabcd', suffixes: ['3a934b']
156
158
  )
157
- assert_equal('c9c72efbf6beeea13408c5e720ec42aec017c11c3db335e05595c03755000000', score.hash)
159
+ assert_equal(
160
+ 'c9c72efbf6beeea13408c5e720ec42aec017c11c3db335e05595c03755000000',
161
+ score.hash
162
+ )
158
163
  score = Zold::Score.new(
159
164
  time: Time.parse('2018-06-27T06:22:41Z'), host: 'b2.zold.io', port: 4096,
160
165
  invoice: 'THdonv1E@abcdabcdabcdabcd', suffixes: %w[3a934b 1421217]
161
166
  )
162
- assert_equal('e04ab4e69f86aa17be1316a52148e7bc3187c6d3df581d885a862d8850000000', score.hash)
167
+ assert_equal(
168
+ 'e04ab4e69f86aa17be1316a52148e7bc3187c6d3df581d885a862d8850000000',
169
+ score.hash
170
+ )
163
171
  end
164
172
 
165
173
  def test_lets_the_thread_to_die
166
- score = Zold::Score.new(host: 'localhost', invoice: 'NOPREFIX@ffffffffffffffff', strength: 30)
174
+ score = Zold::Score.new(
175
+ host: 'localhost', invoice:
176
+ 'NOPREFIX@ffffffffffffffff', strength: 30
177
+ )
167
178
  thread = Thread.start do
168
179
  score.next
169
180
  end
data/zold-score.gemspec CHANGED
@@ -23,11 +23,13 @@
23
23
  require 'English'
24
24
  Gem::Specification.new do |s|
25
25
  s.specification_version = 2 if s.respond_to? :specification_version=
26
- s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
26
+ if s.respond_to? :required_rubygems_version=
27
+ s.required_rubygems_version = Gem::Requirement.new('>= 0')
28
+ end
27
29
  s.rubygems_version = '2.2'
28
30
  s.required_ruby_version = '>=2.3'
29
31
  s.name = 'zold-score'
30
- s.version = '0.4.2'
32
+ s.version = '0.4.3'
31
33
  s.license = 'MIT'
32
34
  s.summary = 'Zold score'
33
35
  s.description = 'Score calculating Ruby Gem for Zold'
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.2
4
+ version: 0.4.3
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-10 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov