phc_string_format 0.1.3 → 0.1.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
2
  SHA1:
3
- metadata.gz: ab5bc37e57a1b618555f9327bd4f39f8c88517f0
4
- data.tar.gz: 5490d74428f42107e165497c54baba19a2c08984
3
+ metadata.gz: 387297ecdd03a3f1a103a1c852be5a2ecd07abc3
4
+ data.tar.gz: 83a0e1784b853a92de75aa9c75829b5999409cab
5
5
  SHA512:
6
- metadata.gz: '018370ed5b2bac8d835e48184a0384ea0523a28bb6d7311b96370364abc37bf3cdf9884a3838c6d5879b2548ee64850495fa82a8ba560da5d4c2c1e22b73e23e'
7
- data.tar.gz: 44c32560f5a43007cd512ab5f21371df00858e1522c1881a47b234c9882281afcb27e6abcd987efca8bdd731b4a456b42ce7268593bcb61e9cf81612a0745802
6
+ metadata.gz: e2d21cde31f35746242a8eaf48bd996b01adc3aa24698133cbf82f1104dbbf6aa304d125d1e767662d7498c2ead5ea8a5e75ae704e93a489a91779fadf958189
7
+ data.tar.gz: 46daddb661e5f9b879cdfd2e8487fbd570b20a3aa88165cabe4c205ea6557e6819db0bbc98d46a7dc9e3df0a6c41b08c13d7ba3efee4c369f43af837abd3d625
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phc_string_format (0.1.3)
4
+ phc_string_format (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,24 +9,20 @@ require "base64"
9
9
  # ```
10
10
  #
11
11
  module PhcStringFormat
12
-
13
12
  module Formatter
14
-
15
- #
16
13
  def self.format(id:, params: {}, salt: '', hash: '', hint: {salt: {encoding: 'base64'}})
17
14
  raise ArgumentError.new, 'id is required' if id.nil?
18
15
  raise ArgumentError.new, 'hash needs salt' if (salt.nil? || salt.empty?) && !(hash.nil? || hash.empty?)
19
16
 
20
17
  elements = [
21
18
  id,
22
- (params.map {|e| e.join '='}.join(',') if params),
19
+ (params.map{|e| e.join '='}.join(',') if params),
23
20
  hint.dig(:salt, :encoding) == '7bit' ? salt : short_strict_encode64(salt),
24
21
  short_strict_encode64(hash)
25
22
  ]
26
- "$#{elements.select {|e| !(e.nil? || e.empty?)} .join('$')}"
23
+ "$#{elements.select{|e| !(e.nil? || e.empty?)}.join('$')}"
27
24
  end
28
25
 
29
- #
30
26
  def self.parse(string, hint: {salt: {encoding: 'base64'}})
31
27
  elements = string.split(/\$/, 5)
32
28
  elements.shift
@@ -34,11 +30,11 @@ module PhcStringFormat
34
30
  params = parse_parameter_string(elements.shift) if (elements.first || '').include?('=')
35
31
  salt = hint.dig(:salt, :encoding) == '7bit' ? elements.shift : short_strict_decode64(elements.shift)
36
32
  hash = short_strict_decode64(elements.shift)
37
- {id: id, params: params, salt: salt, hash: hash }
33
+ {id: id, params: params, salt: salt, hash: hash}.select {|_,v| v}
38
34
  end
39
35
 
40
36
  def self.parse_parameter_string(string)
41
- string.split(/,/).map {|e| e.split '='}.each_with_object({}) {|e, h| k, v = e; h[k.to_sym] = (/\A-?\d+(.\d+)?\Z/.match(v) ? v.to_i : v)}
37
+ string.split(/,/).map {|e| e.split '='}.each_with_object({}){|e, h| k, v = e; h[k] = (/\A-?\d+(.\d+)?\Z/.match(v) ? v.to_i : v)}
42
38
  end
43
39
 
44
40
  def self.short_strict_encode64(bin)
@@ -52,7 +48,5 @@ module PhcStringFormat
52
48
  end
53
49
 
54
50
  private_class_method :short_strict_encode64, :short_strict_decode64, :parse_parameter_string
55
-
56
51
  end
57
-
58
52
  end
@@ -1,3 +1,3 @@
1
1
  module PhcStringFormat
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phc_string_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - naokikimura