zold-score 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/lib/zold/score.rb +1 -29
- data/test/zold/test_score.rb +0 -25
- data/zold-score.gemspec +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: 6705ffd219a4069f1dd5bfcf53f79c919e682f351b1f2802acbe2dd33d4cb32b
|
4
|
+
data.tar.gz: d4e077c6705ef8bedbff3b920f0547d5c535e49d03b4b06bea4026bf13bfff0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f338a0958b7be48d5ae3ef5ab1b433788fbcce2334773ec7deea50283bf595dbefbe2ab08b180192fb580a03dfada6d8018e06c183e7b1aa3ad0783a2278a454
|
7
|
+
data.tar.gz: b703969c9f94f564c8da37910c7bdc7a7cd72db7e8eacff4025e465a52f43c016aea73d49516b1ed7f6f6132e9fa93f7f5b9c72a0e1ec69c1e002a5f284aaca3
|
data/.travis.yml
CHANGED
data/lib/zold/score.rb
CHANGED
@@ -46,7 +46,7 @@ module Zold
|
|
46
46
|
# a node. If the number if too small, the values of the score will be
|
47
47
|
# big and the amount of data to be transferred from node to node will
|
48
48
|
# increase. The number is set empirically.
|
49
|
-
STRENGTH =
|
49
|
+
STRENGTH = 8
|
50
50
|
|
51
51
|
attr_reader :time, :host, :port, :invoice, :suffixes, :strength, :created
|
52
52
|
|
@@ -104,19 +104,6 @@ module Zold
|
|
104
104
|
)
|
105
105
|
end
|
106
106
|
|
107
|
-
# Parses it back from the text generated by <tt>to_text</tt>.
|
108
|
-
def self.parse_text(text)
|
109
|
-
parts = text.split(' ', 7)
|
110
|
-
Score.new(
|
111
|
-
time: Time.at(parts[1].hex),
|
112
|
-
host: parts[2],
|
113
|
-
port: parts[3].hex,
|
114
|
-
invoice: "#{parts[4]}@#{parts[5]}",
|
115
|
-
suffixes: parts[6] ? parts[6].split(' ') : [],
|
116
|
-
strength: parts[0].to_i
|
117
|
-
)
|
118
|
-
end
|
119
|
-
|
120
107
|
# Returns its crypto hash. Read the White Paper for more information.
|
121
108
|
def hash
|
122
109
|
raise 'Score has zero value, there is no hash' if @suffixes.empty?
|
@@ -130,21 +117,6 @@ module Zold
|
|
130
117
|
"#{value}:#{@time.strftime('%H%M')}"
|
131
118
|
end
|
132
119
|
|
133
|
-
# Converts it to a text, which is console friendly. You can parse it back
|
134
|
-
# using <tt>parse_text()</tt>.
|
135
|
-
def to_text
|
136
|
-
pfx, bnf = @invoice.split('@')
|
137
|
-
[
|
138
|
-
@strength,
|
139
|
-
@time.to_i.to_s(16),
|
140
|
-
@host,
|
141
|
-
@port.to_s(16),
|
142
|
-
pfx,
|
143
|
-
bnf,
|
144
|
-
@suffixes.join(' ')
|
145
|
-
].join(' ')
|
146
|
-
end
|
147
|
-
|
148
120
|
# Converts it to a string. You can parse it back
|
149
121
|
# using <tt>parse()</tt>.
|
150
122
|
def to_s
|
data/test/zold/test_score.rb
CHANGED
@@ -104,31 +104,6 @@ class TestScore < Minitest::Test
|
|
104
104
|
assert(ex.message.include?('Invalid score'), ex)
|
105
105
|
end
|
106
106
|
|
107
|
-
def test_prints_and_parses_text
|
108
|
-
time = Time.now
|
109
|
-
score = Zold::Score.parse_text(
|
110
|
-
Zold::Score.new(
|
111
|
-
time: time, host: 'a.example.com', port: 999, invoice: 'NOPREFIX@ffffffffffffffff',
|
112
|
-
strength: 1
|
113
|
-
).next.next.next.to_text
|
114
|
-
)
|
115
|
-
assert_equal(3, score.value)
|
116
|
-
assert_equal(score.time.utc.to_s, time.utc.to_s)
|
117
|
-
assert_equal('a.example.com', score.host)
|
118
|
-
assert_equal(999, score.port)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_prints_and_parses_text_zero_score
|
122
|
-
time = Time.now
|
123
|
-
score = Zold::Score.parse_text(
|
124
|
-
Zold::Score.new(
|
125
|
-
time: time, host: '192.168.0.1', port: 1, invoice: 'NOPREFIX@ffffffffffffffff', suffixes: []
|
126
|
-
).to_text
|
127
|
-
)
|
128
|
-
assert_equal(0, score.value)
|
129
|
-
assert(!score.expired?)
|
130
|
-
end
|
131
|
-
|
132
107
|
def test_prints_and_parses_zero_score
|
133
108
|
time = Time.now
|
134
109
|
score = Zold::Score.parse(
|
data/zold-score.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.rubygems_version = '2.2'
|
28
28
|
s.required_ruby_version = '>=2.3'
|
29
29
|
s.name = 'zold-score'
|
30
|
-
s.version = '0.
|
30
|
+
s.version = '0.4.0'
|
31
31
|
s.license = 'MIT'
|
32
32
|
s.summary = 'Zold score'
|
33
33
|
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
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2018-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|