zold-score 0.4.1 → 0.4.2

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: b95e6e5b07f648e57d06ddbcb8d93cf32fa4330f621fa67dee4fec4014b74979
4
- data.tar.gz: eb9e2ba533897bbbde34dab6873b2c347f1e81cca15eb0380eb55120ee98afe5
3
+ metadata.gz: 7824cd0db572815711d7dc77b9f820543a6f006c5476af408a78a027d00e8a77
4
+ data.tar.gz: 1e5ce652f5365135fb299d3e432e7e09fa485e822673bacbadf53418014d2192
5
5
  SHA512:
6
- metadata.gz: a16f800d385d5d9eb07061e7c0e8d1c2dbfa6e530f7329480fbf65a168f3607fda47bc86384e2f4bba290b258cb2b71c6017e1ebbbedfa253d126867007ca5c9
7
- data.tar.gz: '079dae179cb868a1cd8c5a9d6fc4cbf33419371125e0dee215a9f1556bcdcba97efe6c8c585cb1e5de74bb8b399c9941b4a19f11f6fa966465cb0f3a893ba146'
6
+ metadata.gz: cb927d57fa49f8805563a8664b501b82fd7b2a91a0dd6e43c801d005913b6f95b5a283e4a06d758d7cd7cfaf3e7d0e8413ec7b10781897490b926ee7436b2de1
7
+ data.tar.gz: 34ec30b7f91f1f61ff106aa4a9e3d266092934571a177d6548329ae5f5c6785f7978567d98f355205d2667e406ec0aa06eec9d8f74965ff96c785cee4061291d
@@ -79,28 +79,32 @@ module Zold
79
79
  )
80
80
  end
81
81
 
82
- # Pattern to match from string
83
- PTN = Regexp.new(
84
- '^' + [
85
- '([0-9]+)/(?<strength>[0-9]+):',
86
- ' (?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
87
- ' (?<host>[0-9a-z\.\-]+)',
88
- ' (?<port>[0-9]+)',
89
- ' (?<invoice>[a-zA-Z0-9]{8,32}@[a-f0-9]{16})',
90
- '(?<suffixes>( [a-zA-Z0-9]+)*)'
91
- ].join + '$'
92
- )
93
- private_constant :PTN
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
- m = PTN.match(text.strip)
98
- raise "Invalid score '#{text}', doesn't match: #{PTN}" if m.nil?
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.parse(m[:time]), host: m[:host],
101
- port: m[:port].to_i, invoice: m[:invoice],
102
- suffixes: m[:suffixes].split(' '),
103
- strength: m[:strength].to_i
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
@@ -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.to_s, time.to_s)
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
@@ -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.1'
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold-score
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko