vietnamese_alphabet 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 758802e6786eff6a7ef1e9af2039b265d6ece69f63fd69903c73e4af2f4011a7
4
+ data.tar.gz: 92db373cf6276ea01a2d9fd3a83774e666e87fcefa13f5ed748eb6f55b919e4e
5
+ SHA512:
6
+ metadata.gz: a3f0ec5262c863c448f0f7623d220ff099fff55cab8c18d30b9b664e45a46dd8002074a05265219acf9877e0fef67fea81806f21e3212cc06b02aeb47501a1ad
7
+ data.tar.gz: 6bb51a260a6ccf7f95037efcba303f3739e49fa1359ace27fbc85eaeff2f26056ebcbcc2173df8e59fbf2fd6c4ae921709568d40df77aa0691195aa383a93759
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-07
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # VietnameseAlphabet
2
+
3
+ This library provides methods to convert Vietnamese text with special characters into the Latin alphabet.
4
+
5
+ ## Installation
6
+ Install the gem and add to the application's Gemfile by executing:
7
+
8
+ $ bundle add vietnamese_alphabet
9
+
10
+ If bundler is not being used to manage dependencies, install the gem by executing:
11
+
12
+ $ gem install vietnamese_alphabet
13
+
14
+ ## Usage
15
+
16
+ ```Ruby
17
+ VietnameseAlphabet.convert_variation("Tôi yêu Việt Nam")
18
+ # => "Toi yeu Viet Nam"
19
+ ```
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "vietnamese_alphabet"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VietnameseAlphabet
4
+ VERSION = "0.1.2"
5
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "vietnamese_alphabet/version"
4
+
5
+ module VietnameseAlphabet
6
+ class Error < StandardError; end
7
+
8
+ def self.convert_variation(string)
9
+ return if string.blank?
10
+
11
+ map = {
12
+ 'à' => 'a',
13
+ 'á' => 'a',
14
+ 'ạ' => 'a',
15
+ 'ả' => 'a',
16
+ 'ã' => 'a',
17
+ 'â' => 'a',
18
+ 'ầ' => 'a',
19
+ 'ấ' => 'a',
20
+ 'ậ' => 'a',
21
+ 'ẩ' => 'a',
22
+ 'ẫ' => 'a',
23
+ 'ă' => 'a',
24
+ 'ằ' => 'a',
25
+ 'ắ' => 'a',
26
+ 'ặ' => 'a',
27
+ 'ẳ' => 'a',
28
+ 'ẵ' => 'a',
29
+ 'è' => 'e',
30
+ 'é' => 'e',
31
+ 'ẹ' => 'e',
32
+ 'ẻ' => 'e',
33
+ 'ẽ' => 'e',
34
+ 'ê' => 'e',
35
+ 'ề' => 'e',
36
+ 'ế' => 'e',
37
+ 'ệ' => 'e',
38
+ 'ể' => 'e',
39
+ 'ễ' => 'e',
40
+ 'ì' => 'i',
41
+ 'í' => 'i',
42
+ 'ị' => 'i',
43
+ 'ỉ' => 'i',
44
+ 'ĩ' => 'i',
45
+ 'ò' => 'o',
46
+ 'ó' => 'o',
47
+ 'ọ' => 'o',
48
+ 'ỏ' => 'o',
49
+ 'õ' => 'o',
50
+ 'ô' => 'o',
51
+ 'ồ' => 'o',
52
+ 'ố' => 'o',
53
+ 'ộ' => 'o',
54
+ 'ổ' => 'o',
55
+ 'ỗ' => 'o',
56
+ 'ơ' => 'o',
57
+ 'ờ' => 'o',
58
+ 'ớ' => 'o',
59
+ 'ợ' => 'o',
60
+ 'ở' => 'o',
61
+ 'ỡ' => 'o',
62
+ 'ù' => 'u',
63
+ 'ú' => 'u',
64
+ 'ụ' => 'u',
65
+ 'ủ' => 'u',
66
+ 'ũ' => 'u',
67
+ 'ư' => 'u',
68
+ 'ừ' => 'u',
69
+ 'ứ' => 'u',
70
+ 'ự' => 'u',
71
+ 'ử' => 'u',
72
+ 'ữ' => 'u',
73
+ 'ỳ' => 'y',
74
+ 'ý' => 'y',
75
+ 'ỵ' => 'y',
76
+ 'ỷ' => 'y',
77
+ 'ỹ' => 'y',
78
+ 'đ' => 'd',
79
+ 'Đ' => 'D',
80
+ 'À' => 'A',
81
+ 'Á' => 'A',
82
+ 'Ạ' => 'A',
83
+ 'Ả' => 'A',
84
+ 'Ã' => 'A',
85
+ 'Â' => 'A',
86
+ 'Ầ' => 'A',
87
+ 'Ấ' => 'A',
88
+ 'Ậ' => 'A',
89
+ 'Ẩ' => 'A',
90
+ 'Ẫ' => 'A',
91
+ 'Ă' => 'A',
92
+ 'Ằ' => 'A',
93
+ 'Ắ' => 'A',
94
+ 'Ặ' => 'A',
95
+ 'Ẳ' => 'A',
96
+ 'Ẵ' => 'A',
97
+ 'È' => 'E',
98
+ 'É' => 'E',
99
+ 'Ẹ' => 'E',
100
+ 'Ẻ' => 'E',
101
+ 'Ẽ' => 'E',
102
+ 'Ê' => 'E',
103
+ 'Ề' => 'E',
104
+ 'Ế' => 'E',
105
+ 'Ệ' => 'E',
106
+ 'Ể' => 'E',
107
+ 'Ễ' => 'E',
108
+ 'Ì' => 'I',
109
+ 'Í' => 'I',
110
+ 'Ị' => 'I',
111
+ 'Ỉ' => 'I',
112
+ 'Ĩ' => 'I',
113
+ 'Ò' => 'O',
114
+ 'Ó' => 'O',
115
+ 'Ọ' => 'O',
116
+ 'Ỏ' => 'O',
117
+ 'Õ' => 'O',
118
+ 'Ô' => 'O',
119
+ 'Ồ' => 'O',
120
+ 'Ố' => 'O',
121
+ 'Ộ' => 'O',
122
+ 'Ổ' => 'O',
123
+ 'Ỗ' => 'O',
124
+ 'Ơ' => 'O',
125
+ 'Ờ' => 'O',
126
+ 'Ớ' => 'O',
127
+ 'Ợ' => 'O',
128
+ 'Ở' => 'O',
129
+ 'Ỡ' => 'O',
130
+ 'Ù' => 'U',
131
+ 'Ú' => 'U',
132
+ 'Ụ' => 'U',
133
+ 'Ủ' => 'U',
134
+ 'Ũ' => 'U',
135
+ 'Ư' => 'U',
136
+ 'Ừ' => 'U',
137
+ 'Ứ' => 'U',
138
+ 'Ự' => 'U',
139
+ 'Ử' => 'U',
140
+ 'Ữ' => 'U',
141
+ 'Ỳ' => 'Y',
142
+ 'Ý' => 'Y',
143
+ 'Ỵ' => 'Y',
144
+ 'Ỷ' => 'Y',
145
+ 'Ỹ' => 'Y'
146
+ }.freeze
147
+
148
+ reg = Regexp.new(map.keys.map { |x| Regexp.escape(x) }.join('|'))
149
+
150
+ string.to_s.gsub(reg, map)
151
+ end
152
+
153
+ def self.to_slug(string)
154
+ return if string.blank?
155
+
156
+ converted_string = convert_variation(string)
157
+ converted_string.gsub!(/[^a-zA-Z0-9-]/, ' ')
158
+ converted_string = converted_string.squeeze.strip
159
+ converted_string.gsub!(/\s/,'-')
160
+ converted_string.downcase
161
+ end
162
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vietnamese_alphabet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Thanh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - thanhbk150@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - README.md
22
+ - bin/console
23
+ - bin/setup
24
+ - lib/vietnamese_alphabet.rb
25
+ - lib/vietnamese_alphabet/version.rb
26
+ homepage: https://github.com/thanhbk150/vietnamese_alphabet
27
+ licenses: []
28
+ metadata:
29
+ allowed_push_host: https://rubygems.org/
30
+ homepage_uri: https://github.com/thanhbk150/vietnamese_alphabet
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.6.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.2.33
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: This library provides methods to convert Vietnamese text with special characters
50
+ into the Latin alphabet.
51
+ test_files: []