coaster 1.4.1 → 1.4.3

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: 85992b4a8d2e6d63f199862b11142aaa9b89f4d71d3ee6b5f6f2c3ec40c3c41e
4
- data.tar.gz: ece9a6510d593ca84d3e63cfbaf0da21b529cb729ccaec71022419d3df1d3ac5
3
+ metadata.gz: 92829efea847451135ad1b9cf438666245c66e575840c3cdfbd60fa109552de6
4
+ data.tar.gz: 1c794764a066cf907161257ef96869a7ad88be3f7b5f707addc25756780e649a
5
5
  SHA512:
6
- metadata.gz: 95d49f08fde8dbb712081b6713651c0f2bd46877e302250d9a95b5853aa44129ebad95bc7fa91540e99c0acd80f702d8c8ba4c8245f4a66ab3dd148500f968b6
7
- data.tar.gz: e0a609c0f8c895851c2679704c3fb5b95e1c239e5fe6597eba89eb96b703dfd4b62f7352dbde766e04997f2362b09002186322302bd6c2e930afad6d1e477a58
6
+ metadata.gz: c3bb4d68ff70be7bf10136291fd208f845ae7cd69f2548f4fae5be14e69b1613c735cabfc31ff1abc3e47a5dcc0204b01460e5da3167fd6e752eb2fc54446898
7
+ data.tar.gz: bfadd8eb9082e38f882aab594a8617b8e6a38d1a56d837a1402f42a9b880bded477cde6dbb9f0d641ae26b77ae016f6adca9d3c0b2e59c3d0e098e1658611230
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ class String
5
+ # @note 반각 문자 -> 전각 문자
6
+ # @param [TrueClass, FalseClass] alpha
7
+ # @param [TrueClass, FalseClass] number
8
+ # @param [TrueClass, FalseClass] symbol
9
+ # @return [String]
10
+ def to_full_characters(alpha: true, number: true, symbol: false)
11
+ result = String.new
12
+ return result if self.blank?
13
+
14
+ (0...self.size).each do |i|
15
+ half_ord = self[i].ord
16
+ full_ord = half_ord + 0xfee0
17
+ char_ord = case half_ord
18
+ when 0x20 then 0x3000
19
+ when ('0'.ord)..('9'.ord) then number ? full_ord : half_ord
20
+ when ('A'.ord)..('Z'.ord) then alpha ? full_ord : half_ord
21
+ when ('a'.ord)..('z'.ord) then alpha ? full_ord : half_ord
22
+ when ('!'.ord)..('~'.ord) then symbol ? full_ord : half_ord
23
+ else half_ord
24
+ end
25
+ result << char_ord.chr('UTF-8')
26
+ end
27
+ result
28
+ end
29
+
30
+ # @note 전각 문자 -> 반각 문자
31
+ # @param [TrueClass, FalseClass] alpha
32
+ # @param [TrueClass, FalseClass] number
33
+ # @param [TrueClass, FalseClass] symbol
34
+ # @return [String]
35
+ def to_half_characters(alpha: true, number: true, symbol: false)
36
+ result = String.new
37
+ return result if self.blank?
38
+
39
+ (0...self.size).each do |i|
40
+ full_ord = self[i].ord
41
+ half_ord = full_ord - 0xfee0
42
+ char_ord = case full_ord
43
+ when 0x3000 then 0x20
44
+ when ('0'.ord + 0xfee0)..('9'.ord + 0xfee0) then number ? half_ord : full_ord
45
+ when ('A'.ord + 0xfee0)..('Z'.ord + 0xfee0) then alpha ? half_ord : full_ord
46
+ when ('a'.ord + 0xfee0)..('z'.ord + 0xfee0) then alpha ? half_ord : full_ord
47
+ when ('!'.ord + 0xfee0)..('~'.ord + 0xfee0) then symbol ? half_ord : full_ord
48
+ else full_ord
49
+ end
50
+ result << char_ord.chr('UTF-8')
51
+ end
52
+ result
53
+ end
54
+ end
@@ -4,3 +4,4 @@ require_relative 'core_ext/date'
4
4
  require_relative 'core_ext/month'
5
5
  require_relative 'core_ext/object_translation'
6
6
  require_relative 'core_ext/standard_error'
7
+ require_relative 'core_ext/string'
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.4.1'
2
+ VERSION = '1.4.3'
3
3
  end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+
4
+ module Coaster
5
+ class TestString < Minitest::Test
6
+ def test_string
7
+ # half -> full width (to_full_characters)
8
+ half_seq = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
9
+ full_seq = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
10
+ not_target_half_seq = ((33..255).map { |c| c.chr('UTF-8') }.join.chars - half_seq.chars).join + '일이삼いちにさんイチニサン一二三'
11
+ mixed_str = half_seq + not_target_half_seq
12
+ # half -> full 1:1 잘 변환되는가?
13
+ assert_equal half_seq.to_full_characters, full_seq
14
+ # half -> full -> half 변환 시, 원래 string 유지되는가?
15
+ assert_equal half_seq.to_full_characters.to_half_characters, half_seq
16
+ # not_target string은 to full 변환 시도시 원본이 유지되는가?
17
+ assert_equal not_target_half_seq.to_full_characters, not_target_half_seq
18
+ # target / not_target이 섞여있는 문장에서, target'만' full로 변환되는가?
19
+ assert_equal mixed_str.to_full_characters, full_seq + not_target_half_seq
20
+ # target / not_target이 섞여있는 문장에서, half -> full -> half 변환시, 원래 string 유지되는가?
21
+ assert_equal mixed_str.to_full_characters.to_half_characters, mixed_str
22
+ # 공백문자열에 다른게 추가되지는 않는가?
23
+ assert_equal ''.to_full_characters, ''
24
+
25
+ # half -> full width (to_full_characters with symbol)
26
+ half_seq = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
27
+ full_seq = ' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
28
+ not_target_half_seq = ((33..255).map { |c| c.chr('UTF-8') }.join.chars - half_seq.chars).join + '일이삼いちにさんイチニサン一二三'
29
+ mixed_str = half_seq + not_target_half_seq
30
+ # half -> full 1:1 잘 변환되는가?
31
+ assert_equal half_seq.to_full_characters(symbol: true), full_seq
32
+ # half -> full -> half 변환 시, 원래 string 유지되는가?
33
+ assert_equal half_seq.to_full_characters(symbol: true).to_half_characters(symbol: true), half_seq
34
+ # not_target string은 to full 변환 시도시 원본이 유지되는가?
35
+ assert_equal not_target_half_seq.to_full_characters(symbol: true), not_target_half_seq
36
+ # target / not_target이 섞여있는 문장에서, target'만' full로 변환되는가?
37
+ assert_equal mixed_str.to_full_characters(symbol: true), full_seq + not_target_half_seq
38
+ # target / not_target이 섞여있는 문장에서, half -> full -> half 변환시, 원래 string 유지되는가?
39
+ assert_equal mixed_str.to_full_characters(symbol: true).to_half_characters(symbol: true), mixed_str
40
+ # 공백문자열에 다른게 추가되지는 않는가?
41
+ assert_equal ''.to_full_characters, ''
42
+
43
+ # full -> half width (to_half_characters)
44
+ half_seq = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
45
+ full_seq = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
46
+ not_target_full_seq = ((33..255).map { |c| (c + 0xfee0).chr('UTF-8') }.join.chars - full_seq.chars).join + '일이삼いちにさんイチニサン一二三'
47
+ mixed_str = full_seq + not_target_full_seq
48
+ # full -> half 1:1 잘 변환되는가?
49
+ assert_equal full_seq.to_half_characters, half_seq
50
+ # full -> half -> full 변환 시, 원래 string 유지되는가?
51
+ assert_equal full_seq.to_half_characters.to_full_characters, full_seq
52
+ # not_target string은 to half 변환 시도시 원본이 유지되는가?
53
+ assert_equal not_target_full_seq.to_half_characters, not_target_full_seq
54
+ # target / not_target이 섞여있는 문장에서, target'만' half로 변환되는가?
55
+ assert_equal mixed_str.to_half_characters, half_seq + not_target_full_seq
56
+ # target / not_target이 섞여있는 문장에서, full -> half -> full 변환시, 원래 string 유지되는가?
57
+ assert_equal mixed_str.to_half_characters.to_full_characters, mixed_str
58
+ # 공백문자열에 다른게 추가되지는 않는가?
59
+ assert_equal ''.to_half_characters, ''
60
+
61
+ # full -> half width (to_half_characters with symbol)
62
+ half_seq = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
63
+ full_seq = ' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
64
+ not_target_full_seq = ((33..255).map { |c| (c + 0xfee0).chr('UTF-8') }.join.chars - full_seq.chars).join + '일이삼いちにさんイチニサン一二三'
65
+ mixed_str = full_seq + not_target_full_seq
66
+ # full -> half 1:1 잘 변환되는가?
67
+ expect(full_seq.to_half_characters(symbol: true)).to eq half_seq
68
+ assert_equal full_seq.to_half_characters(symbol: true), half_seq
69
+ # full -> half -> full 변환 시, 원래 string 유지되는가?
70
+ expect(full_seq.to_half_characters(symbol: true).to_full_characters(symbol: true)).to eq full_seq
71
+ assert_equal full_seq.to_half_characters(symbol: true).to_full_characters(symbol: true), full_seq
72
+ # not_target string은 to half 변환 시도시 원본이 유지되는가?
73
+ expect(not_target_full_seq.to_half_characters(symbol: true)).to eq not_target_full_seq
74
+ assert_equal not_target_full_seq.to_half_characters(symbol: true), not_target_full_seq
75
+ # target / not_target이 섞여있는 문장에서, target'만' half로 변환되는가?
76
+ expect(mixed_str.to_half_characters(symbol: true)).to eq half_seq + not_target_full_seq
77
+ assert_equal mixed_str.to_half_characters(symbol: true), half_seq + not_target_full_seq
78
+ # target / not_target이 섞여있는 문장에서, full -> half -> full 변환시, 원래 string 유지되는가?
79
+ expect(mixed_str.to_half_characters(symbol: true).to_full_characters(symbol: true)).to eq mixed_str
80
+ assert_equal mixed_str.to_half_characters(symbol: true).to_full_characters(symbol: true), mixed_str
81
+ # 공백문자열에 다른게 추가되지는 않는가?
82
+ expect(''.to_half_characters(symbol: true)).to eq ''
83
+ assert_equal ''.to_half_characters(symbol: true), ''
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-05 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -200,6 +200,7 @@ files:
200
200
  - lib/coaster/core_ext/standard_error.rb
201
201
  - lib/coaster/core_ext/standard_error/raven.rb
202
202
  - lib/coaster/core_ext/standard_error/sentry.rb
203
+ - lib/coaster/core_ext/string.rb
203
204
  - lib/coaster/git.rb
204
205
  - lib/coaster/git/options.rb
205
206
  - lib/coaster/git/repository.rb
@@ -221,6 +222,7 @@ files:
221
222
  - test/test_object_translation.rb
222
223
  - test/test_serialized_property.rb
223
224
  - test/test_standard_error.rb
225
+ - test/test_string.rb
224
226
  - test/test_util.rb
225
227
  homepage: http://github.com/frograms/coaster
226
228
  licenses:
@@ -260,4 +262,5 @@ test_files:
260
262
  - test/test_object_translation.rb
261
263
  - test/test_serialized_property.rb
262
264
  - test/test_standard_error.rb
265
+ - test/test_string.rb
263
266
  - test/test_util.rb