zold-score 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/score.rb +22 -31
- data/test/zold/test_score.rb +1 -1
- data/zold-score.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7824cd0db572815711d7dc77b9f820543a6f006c5476af408a78a027d00e8a77
|
4
|
+
data.tar.gz: 1e5ce652f5365135fb299d3e432e7e09fa485e822673bacbadf53418014d2192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb927d57fa49f8805563a8664b501b82fd7b2a91a0dd6e43c801d005913b6f95b5a283e4a06d758d7cd7cfaf3e7d0e8413ec7b10781897490b926ee7436b2de1
|
7
|
+
data.tar.gz: 34ec30b7f91f1f61ff106aa4a9e3d266092934571a177d6548329ae5f5c6785f7978567d98f355205d2667e406ec0aa06eec9d8f74965ff96c785cee4061291d
|
data/lib/zold/score.rb
CHANGED
@@ -79,28 +79,32 @@ module Zold
|
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
# Converts it to a string. You can parse it back
|
83
|
+
# using <tt>parse()</tt>.
|
84
|
+
def to_s
|
85
|
+
pfx, bnf = @invoice.split('@')
|
86
|
+
[
|
87
|
+
@strength,
|
88
|
+
@time.to_i.to_s(16),
|
89
|
+
@host,
|
90
|
+
@port.to_s(16),
|
91
|
+
pfx,
|
92
|
+
bnf,
|
93
|
+
@suffixes.join(' ')
|
94
|
+
].join(' ')
|
95
|
+
end
|
94
96
|
|
95
97
|
# Parses it back from the text generated by <tt>to_s</tt>.
|
96
98
|
def self.parse(text)
|
97
|
-
|
98
|
-
raise "Invalid score
|
99
|
+
parts = text.split(' ', 7)
|
100
|
+
raise "Invalid score, not enough parts in \"#{text}\"" if parts.length < 7
|
99
101
|
Score.new(
|
100
|
-
time: Time.
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
time: Time.at(parts[1].hex),
|
103
|
+
host: parts[2],
|
104
|
+
port: parts[3].hex,
|
105
|
+
invoice: "#{parts[4]}@#{parts[5]}",
|
106
|
+
suffixes: parts[6] ? parts[6].split(' ') : [],
|
107
|
+
strength: parts[0].to_i
|
104
108
|
)
|
105
109
|
end
|
106
110
|
|
@@ -117,19 +121,6 @@ module Zold
|
|
117
121
|
"#{value}:#{@time.strftime('%H%M')}"
|
118
122
|
end
|
119
123
|
|
120
|
-
# Converts it to a string. You can parse it back
|
121
|
-
# using <tt>parse()</tt>.
|
122
|
-
def to_s
|
123
|
-
[
|
124
|
-
"#{value}/#{@strength}:",
|
125
|
-
@time.utc.iso8601,
|
126
|
-
@host,
|
127
|
-
@port,
|
128
|
-
@invoice,
|
129
|
-
@suffixes.join(' ')
|
130
|
-
].join(' ').strip
|
131
|
-
end
|
132
|
-
|
133
124
|
# Converts the score to a hash, which can be used for JSON presentation
|
134
125
|
# of the score.
|
135
126
|
def to_h
|
data/test/zold/test_score.rb
CHANGED
@@ -92,7 +92,7 @@ class TestScore < Minitest::Test
|
|
92
92
|
).next.next.to_s
|
93
93
|
)
|
94
94
|
assert_equal(2, score.value)
|
95
|
-
assert_equal(score.time.
|
95
|
+
assert_equal(score.time.utc.iso8601, time.utc.iso8601)
|
96
96
|
assert_equal('localhost', score.host)
|
97
97
|
assert_equal(999, score.port)
|
98
98
|
end
|
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.4.
|
30
|
+
s.version = '0.4.2'
|
31
31
|
s.license = 'MIT'
|
32
32
|
s.summary = 'Zold score'
|
33
33
|
s.description = 'Score calculating Ruby Gem for Zold'
|