phc_string_format 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: 0515e210193222efab52644db4ba99e092ab3bd5
4
- data.tar.gz: e47d47ad2ab63d3b65397d676f930022df5870ec
3
+ metadata.gz: 373b8c4868684651da8c936757f35579e3ef3c77
4
+ data.tar.gz: e529b9855fdb87423ecb7c18b27befbf00358043
5
5
  SHA512:
6
- metadata.gz: '018471d84a39f7c29718404ecdd82c6e32963f165bdf90738419664fea541e75b4037149423ecdbbe9e470aee08ebcb4b126ce26283530d1a68bc9c4f6248201'
7
- data.tar.gz: 2eabb9ebdbb8b4584b11c833ae402de04a5fabbc458d1ff3ad8b0254e82ca2f07adcf81d794da89e3534fc258c1f7929e12ceb6d596658cdd61bc239c91165da
6
+ metadata.gz: 95200c10a93e1b8e60576af7f48b4198004b0fb9496cb4d8ea389d1eaef367a8baac153268ba43b34fbc9ed855d6ad3ec563a8019230bc8cfa9917cd1a46c33b
7
+ data.tar.gz: 2dd6b546b3f274c9431937ff4cb7850e4a2b2707a69f36e85dcdc910317c4a512d91a235b667c24c954e91a908a973f2af02625b3d6b675f8692b81625278157
data/Gemfile.lock CHANGED
@@ -1,12 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- phc_string_format (0.1.0)
4
+ phc_string_format (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ byebug (10.0.2)
10
+ coderay (1.1.2)
9
11
  diff-lcs (1.3)
12
+ method_source (0.9.0)
13
+ pry (0.11.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ pry-byebug (3.6.0)
17
+ byebug (~> 10.0)
18
+ pry (~> 0.10)
10
19
  rake (10.5.0)
11
20
  rspec (3.7.0)
12
21
  rspec-core (~> 3.7.0)
@@ -28,6 +37,7 @@ PLATFORMS
28
37
  DEPENDENCIES
29
38
  bundler (~> 1.16)
30
39
  phc_string_format!
40
+ pry-byebug (~> 3.6)
31
41
  rake (~> 10.0)
32
42
  rspec (~> 3.0)
33
43
 
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # PhcStringFormat
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/phc_string_format.svg)](https://badge.fury.io/rb/phc_string_format)
4
+ [![Build Status](https://travis-ci.org/naokikimura/phc_string_format.svg?branch=master)](https://travis-ci.org/naokikimura/phc_string_format)
5
+ [![Known Vulnerabilities](https://snyk.io/test/github/naokikimura/phc_string_format/badge.svg?targetFile=Gemfile.lock)](https://snyk.io/test/github/naokikimura/phc_string_format?targetFile=Gemfile.lock)
6
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/cbcb6fa3556447a4af16980f3cc6f1eb)](https://app.codacy.com/app/naokikimura/phc_string_format?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/phc_string_format&utm_campaign=badger)
7
+
3
8
  TODO: Describe your gem
4
9
 
5
10
  ## Installation
@@ -13,30 +13,34 @@ module PhcStringFormat
13
13
  module Formatter
14
14
 
15
15
  #
16
- def self.format(id:, params: {}, salt: '', hash: '')
16
+ def self.format(id:, params: {}, salt: '', hash: '', hint: {salt: {encoding: 'base64'}})
17
17
  raise ArgumentError.new, 'id is required' if id.nil?
18
18
  raise ArgumentError.new, 'hash needs salt' if (salt.nil? || salt.empty?) && !(hash.nil? || hash.empty?)
19
19
 
20
20
  elements = [
21
21
  id,
22
- params.entries.map { |k, v| "#{k}=#{v}" }.join(','),
23
- short_strict_encode64(salt),
22
+ (params.map {|e| e.join '='}.join(',') if params),
23
+ hint.dig(:salt, :encoding) == '7bit' ? salt : short_strict_encode64(salt),
24
24
  short_strict_encode64(hash)
25
25
  ]
26
- "$#{elements.select { |e| !(e.nil? || e.empty?) } .join('$')}"
26
+ "$#{elements.select {|e| !(e.nil? || e.empty?)} .join('$')}"
27
27
  end
28
28
 
29
29
  #
30
- def self.parse(string)
31
- elements = string.split('$')
30
+ def self.parse(string, hint: {salt: {encoding: 'base64'}})
31
+ elements = string.split(/\$/, 5)
32
32
  elements.shift
33
33
  id = elements.shift
34
- params = elements.shift.split(',').map {|e| e.split('=')}.reduce({}) {|h, e| k, v = e; h[k]=v; h}
35
- salt = short_strict_decode64(elements.shift)
34
+ params = parse_parameter_string(elements.shift) if elements.first.include?('=')
35
+ salt = hint.dig(:salt, :encoding) == '7bit' ? elements.shift : short_strict_decode64(elements.shift)
36
36
  hash = short_strict_decode64(elements.shift)
37
37
  {id: id, params: params, salt: salt, hash: hash }
38
38
  end
39
39
 
40
+ def self.parse_parameter_string(string)
41
+ string.split(/,/).map {|e| e.split '='}.each_with_object({}) {|e, h| k, v = e; h[k]=v}
42
+ end
43
+
40
44
  def self.short_strict_encode64(bin)
41
45
  return nil unless bin
42
46
  Base64.strict_encode64(bin).delete('=')
@@ -47,7 +51,7 @@ module PhcStringFormat
47
51
  Base64.strict_decode64(bin + '=' * (-bin.size % 4))
48
52
  end
49
53
 
50
- private_class_method :short_strict_encode64, :short_strict_decode64
54
+ private_class_method :short_strict_encode64, :short_strict_decode64, :parse_parameter_string
51
55
 
52
56
  end
53
57
 
@@ -1,3 +1,3 @@
1
1
  module PhcStringFormat
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.16"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry-byebug", "~> 3.6"
33
34
  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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - naokikimura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.6'
55
69
  description:
56
70
  email:
57
71
  - n.kimura.cap@gmail.com