phc_string_format 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 33dff8312aa061f66c90fdabb7d4630ffdb322c2d770e1714fd7f8115335a72e
4
- data.tar.gz: 87d4da1c7bd827cad52cf8f748184d11d661f7d1757627b87be932aaeaf16728
2
+ SHA1:
3
+ metadata.gz: 74aad184bd05ef181197a6511faf147117419a36
4
+ data.tar.gz: 67d273fc6645159868754577049e5c6161454831
5
5
  SHA512:
6
- metadata.gz: bb3038a561c2b36c94d064fa101dec7aa6dd7c49fd4df7b3da269e3d3595ccd8a54b79c1eebd905a42ea1abec0bcfb2fabe4f6cb54cc728d7a172485ced83105
7
- data.tar.gz: a4c5bc3223bf5a614b485fe3a55afaf04f039d0123a734bef209d7db42ba85e076b7dfaed2685076433a87189762f43d314b5607c304706b3b41283d1ae5b527
6
+ metadata.gz: 727d3a0d2e0d0803f0331b897175cd79e36f17feccee6e0b91a02b0ebef6e9e75b083472b527b5ff04939c135696a620fae06b22159222b775d386c69c27771b
7
+ data.tar.gz: f1a8cf1788ace3f1ed3c4ad777492d53daf16782f88f4c539b8c3752895c0172dd8673d247cd046d6b74fd2e2052f6f8a5954f891f3ac3745c5a54457b8594c9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phc_string_format (0.3.3)
4
+ phc_string_format (0.3.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -23,23 +23,24 @@ module PhcStringFormat
23
23
  that
24
24
  end
25
25
 
26
- private_class_method :validates, :validate
27
-
28
- # :reek:DuplicateMethodCall { allow_calls: ['elements.shift', 'elements.first'] }
29
26
  def self.parse(string)
30
27
  string ||= ''
28
+ PhcString.new(*split(string))
29
+ rescue StandardError => exception
30
+ raise ParseError, exception.message
31
+ end
32
+
33
+ # :reek:DuplicateMethodCall { allow_calls: ['elements.shift', 'elements.first'] }
34
+ def self.split(string)
31
35
  elements = string.split(/\$/, 6)
32
36
  elements.shift
33
- id = elements.shift
34
- version = elements.shift if (elements.first || '').start_with?('v=')
35
- params = elements.shift if (elements.first || '').include?('=')
36
- salt = elements.shift
37
- hash = elements.shift
38
- begin
39
- PhcString.new(id, version, params, salt, hash)
40
- rescue ArgumentError
41
- raise ParseError
42
- end
37
+ [
38
+ elements.shift,
39
+ (elements.shift if (elements.first || '').start_with?('v=')),
40
+ (elements.shift if (elements.first || '').include?('=')),
41
+ elements.shift,
42
+ elements.shift
43
+ ]
43
44
  end
44
45
 
45
46
  def self.create(id:, version: nil, params: nil, salt: nil, hash: nil, hint: {})
@@ -52,6 +53,8 @@ module PhcStringFormat
52
53
  )
53
54
  end
54
55
 
56
+ private_class_method :validates, :validate, :split
57
+
55
58
  validates :@id, message: 'id is non-compliant', format: { with: /\A[a-z0-9-]{1,32}\z/ }
56
59
  validates \
57
60
  :@version_string,
@@ -63,12 +66,12 @@ module PhcStringFormat
63
66
  :@encoded_salt,
64
67
  message: 'encoded salt is non-compliant',
65
68
  allow_nil: true,
66
- format: { with: %r{\A[a-zA-Z0-9/+.-]+\z} }
69
+ format: { with: %r{\A[a-zA-Z0-9/+.-]*\z} }
67
70
  validates \
68
71
  :@encoded_hash,
69
72
  message: 'encoded hash is non-compliant',
70
73
  allow_nil: true,
71
- format: { with: %r{\A[a-zA-Z0-9/+]+\z} }
74
+ format: { with: %r{\A[a-zA-Z0-9/+]*\z} }
72
75
  validate :validate_salt_and_hash, message: 'hash needs salt'
73
76
 
74
77
  def initialize(id, version_string, params_string, encoded_salt, encoded_hash)
@@ -88,7 +91,7 @@ module PhcStringFormat
88
91
  @params_string,
89
92
  @encoded_salt,
90
93
  @encoded_hash
91
- ].reject { |element| !element || element.empty? }.join('$')
94
+ ].compact.join('$')
92
95
  end
93
96
 
94
97
  def to_h(pick: nil, hint: {})
@@ -118,7 +121,7 @@ module PhcStringFormat
118
121
  end
119
122
 
120
123
  def validate_salt_and_hash
121
- !((!@encoded_salt || @encoded_salt.empty?) && !(!@encoded_hash || @encoded_hash.empty?))
124
+ @encoded_salt || !@encoded_hash
122
125
  end
123
126
 
124
127
  def parse_version(version_string)
@@ -1,3 +1,3 @@
1
1
  module PhcStringFormat
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phc_string_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - naokikimura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.7.6
117
+ rubygems_version: 2.5.2.3
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: PHC string format implemented by Ruby.