zold-score 0.2.0 → 0.2.1

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: 7fe1d5fbb964d79075197094984971e5e57f8abeb4c9dbf5c21789cb6f54bb28
4
- data.tar.gz: 7e128645840aad4bd99edad037f84294f6d07fdb77b20bf2b1cc38bdcae4744c
3
+ metadata.gz: ae6b7b325d1fc6a2fe0ebc40a24d74dc0fd9aa6d55ab12f3db8ee5e99a9b6b9c
4
+ data.tar.gz: 97fb4c79c78a25e1c50909585772a3dcd5c80dbf3865cc3eec813459b5484a86
5
5
  SHA512:
6
- metadata.gz: d62d7808984f942e665302445c55999b9d112a61071266bfc532751011cc3a7e79f495a99f11ba16c99bc31380b3674a673973e795bdd84e52d2977e6dc92f24
7
- data.tar.gz: cc215cafb076a942887bcccf1f92c9fe90cbc253072c922c967174480761b6976d8fb4cdc1741c87ebae4dc7a98230e85b7e2709d257f916292bf0cdf9e2ddd1
6
+ metadata.gz: 71d647ded91e78b60a2bc4997a0438ec6c5e7de38e26c103491fcd02aca6c5bfc130ca33e2c79c0190bd432cb7823530d64a51e3c2315b03aa2f0afdcfe47eb0
7
+ data.tar.gz: 66f9b065d6262d66b8be14e261d17f043a3323f38ce9da166b29585b2518bdf0b38162113cf8fed5c29d064aea8998ff55c571f173f0c92b3a4fefa163df6c6e
@@ -2,6 +2,8 @@ AllCops:
2
2
  DisplayCopNames: true
3
3
  TargetRubyVersion: 2.3.3
4
4
 
5
+ Layout/EndOfLine:
6
+ EnforcedStyle: lf
5
7
  Metrics/LineLength:
6
8
  Max: 120
7
9
  Metrics/AbcSize:
data/README.md CHANGED
@@ -21,6 +21,27 @@ The license is [MIT](https://github.com/zold-io/zold-score/blob/master/LICENSE.t
21
21
 
22
22
  This small Ruby Gem calculates the score for Zold nodes.
23
23
 
24
+ To calculate a new Score you create an object first:
25
+
26
+ ```ruby
27
+ score = Zold::Score.new(
28
+ host: 'example.com',
29
+ port: 4096,
30
+ invoice: 'MYPREFIX@ffffffffffffffff',
31
+ strength: 6
32
+ )
33
+ ```
34
+
35
+ This score has zero value and the strength of six. Then you just ask it to calculate the next score:
36
+
37
+ ```ruby
38
+ n = score.next
39
+ ```
40
+
41
+ That's it.
42
+
43
+ This project is actively used in our [main Ruby repo](https://github.com/zold-io/zold).
44
+
24
45
  # How to contribute
25
46
 
26
47
  Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
@@ -73,19 +73,21 @@ module Zold
73
73
  )
74
74
  end
75
75
 
76
+ # Pattern to match from string
77
+ PTN = Regexp.new(
78
+ '^' + [
79
+ '([0-9]+)/(?<strength>[0-9]+):',
80
+ ' (?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
81
+ ' (?<host>[0-9a-z\.\-]+)',
82
+ ' (?<port>[0-9]+)',
83
+ ' (?<invoice>[a-zA-Z0-9]{8,32}@[a-f0-9]{16})',
84
+ '(?<suffixes>( [a-zA-Z0-9]+)*)'
85
+ ].join + '$'
86
+ )
87
+
76
88
  # Parses it back from the text generated by <tt>to_s</tt>.
77
89
  def self.parse(text)
78
- re = Regexp.new(
79
- '^' + [
80
- '([0-9]+)/(?<strength>[0-9]+):',
81
- ' (?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
82
- ' (?<host>[0-9a-z\.\-]+)',
83
- ' (?<port>[0-9]+)',
84
- ' (?<invoice>[a-zA-Z0-9]{8,32}@[a-f0-9]{16})',
85
- '(?<suffixes>( [a-zA-Z0-9]+)*)'
86
- ].join + '$'
87
- )
88
- m = re.match(text.strip)
90
+ m = Score::PTN.match(text.strip)
89
91
  raise "Invalid score '#{text}', doesn't match: #{re}" if m.nil?
90
92
  Score.new(
91
93
  time: Time.parse(m[:time]), host: m[:host],
@@ -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.2.0'
30
+ s.version = '0.2.1'
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.2.0
4
+ version: 0.2.1
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-04 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov