arabic 0.1.6 → 0.2.0

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: c156fd97afe3b784b3bfd00f5e427d4575269fd524fb636f6b054aeba2460fc5
4
- data.tar.gz: ebd076b078b1ea807903d15748ab42b676de20f6ed2a5bbd1c7b72fa0132c70a
3
+ metadata.gz: a08be5b924a8dd99c80751f0e151d1d72232c6c8a48f3b303bbc66a3534a2f87
4
+ data.tar.gz: 36b4ce7cff0deeae8978ca0aef18c873d4e08e650c93a211cdba7f188801b40c
5
5
  SHA512:
6
- metadata.gz: 0205f234e84e43558235c0d79abf5ccc8e4ffc0c953337b6582f629d385ea599b62fca5310bb177ce402945786ade4fe4becf34967253c1d5954ff0d40da75a1
7
- data.tar.gz: c4db824469f061a3b722b13e046ae8c4a14e813875be56de1283d843b5b9c0e13e18e12e56153ed8324aad7ce6e2ad57900697738aae132f33ab06bc5efb1770
6
+ metadata.gz: 77f173afdac333ef8db23a11bb4c29b71b67bf2a3f55aa8eb4dea357d1dc19887d7ea63a18fa5492f4af99d698466ba28918d2800bf3f9a22c4d60c55bddf5df
7
+ data.tar.gz: 78a62f2ff52282ba5c29cdf403aa8280eb495bf1a49b330534cc15b41fddbc737a2bb30d5a288d7299a7e94636b92fd3c3ef063d08e4e425bbcf54059183ca72
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ Exclude:
5
+ - 'bin/console'
6
+ - 'bin/setup'
7
+ - 'pkg/**/*'
8
+ - 'vendor/**/*'
9
+ - 'coverage/**/*'
10
+
11
+ Gemspec/DevelopmentDependencies:
12
+ EnforcedStyle: gemspec
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/StringLiterals:
18
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,83 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.0] - 2026-09-17
11
+
12
+ ### Added
13
+ - Persian transliteration scheme (`:persian`) with full 32-letter alphabet and Persian numerals support.
14
+ - CLI executable `exe/arabic` supporting direct arguments, files, piped STDIN, and scheme flag (`-s`).
15
+ - Integration tests for CLI arguments, flags, and STDIN input.
16
+ - GitHub Actions CI workflow for modern Ruby versions on `main` branch with experimental `head`.
17
+ - Automated GitHub Actions release workflow for building and publishing gem on git tag push.
18
+ - Precompiled and cached regular expressions for character tables for improved performance.
19
+ - Case-insensitive scheme resolution (e.g. `:urdu`, `"urdu"`, `:URDU`, `:persian`).
20
+ - Informative `ArgumentError` when an unknown transliteration scheme is specified.
21
+ - Standard gem metadata URIs (`source_code_uri`, `changelog_uri`, `bug_tracker_uri`).
22
+ - RuboCop code style checks integrated into default `rake` task.
23
+ - SimpleCov code test coverage tracking with 100% line coverage.
24
+ - Unit tests for edge cases (nil/empty strings, scheme normalization, error handling).
25
+
26
+ ### Changed
27
+ - Update development dependencies (rubocop, rake, rdoc, irb, json, minitest).
28
+ - Namespaced `Urdu`, `Iso233`, and `Persian` modules under `Arabic` (`Arabic::Urdu`, `Arabic::Iso233`, `Arabic::Persian`) with backwards-compatible top-level aliases.
29
+ - Set minimum required Ruby version to `>= 3.3.0` in gemspec.
30
+ - Untrack `Gemfile.lock` and add to `.gitignore` following gem development best practices.
31
+ - Update copyright year to 2018-2026 in `LICENSE.txt`.
32
+ - Clean up invisible `\u200E` (Left-to-Right Mark) control characters in Arabic vowel table.
33
+ - Clean up placeholder dotted circle `\u25CC` characters in ISO 233 hamza diacritics.
34
+
35
+ ### Removed
36
+ - Legacy `.travis.yml` configuration.
37
+
38
+ ## [0.1.7] - 2025-04-03
39
+
40
+ ### Changed
41
+ - Update gem dependencies and bump version.
42
+
43
+ ## [0.1.6] - 2018-09-13
44
+
45
+ ### Added
46
+ - ISO 233 transliteration scheme (`:iso233`).
47
+ - Additional test cases for Arabic phrases.
48
+
49
+ ## [0.1.5] - 2018-09-13
50
+
51
+ ### Changed
52
+ - Refactor language architecture: separate Urdu transliteration into a dedicated module and file.
53
+
54
+ ## [0.1.4] - 2018-09-05
55
+
56
+ ### Changed
57
+ - Standardize character output to use ASCII characters.
58
+
59
+ ## [0.1.3] - 2018-08-17
60
+
61
+ ### Added
62
+ - Additional Urdu characters support.
63
+ - Additional test coverage for Urdu transliteration.
64
+
65
+ ### Fixed
66
+ - Fix Urdu numerals and character mappings.
67
+
68
+ ## [0.1.2] - 2018-08-16
69
+
70
+ ### Added
71
+ - Additional Urdu symbols (including 'ئ').
72
+
73
+ ## [0.1.1] - 2018-08-16
74
+
75
+ ### Added
76
+ - Initial Urdu transliteration support.
77
+
78
+ ## [0.1.0] - 2018-04-04
79
+
80
+ ### Added
81
+ - Initial release.
82
+ - Core Arabic transliteration to Roman (Latin) script.
83
+ - Support for Arabic numerals, punctuation, consonants, and vowels.
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at zakbox@gmail.com. All
58
+ reported by contacting the project team. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 rovetz
3
+ Copyright (c) 2018-2026 rovetz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Arabic
2
2
 
3
+ [![Ruby](https://github.com/rovetz/arabic/actions/workflows/ruby.yml/badge.svg)](https://github.com/rovetz/arabic/actions/workflows/ruby.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/arabic.svg)](https://badge.fury.io/rb/arabic)
5
+
3
6
  Romanization of Arabic. It transliterates Arabic text to the Roman (Latin) script.
4
7
 
5
8
  ## Installation
@@ -7,7 +10,7 @@ Romanization of Arabic. It transliterates Arabic text to the Roman (Latin) scrip
7
10
  Add this line to your application's Gemfile:
8
11
 
9
12
  ```ruby
10
- gem 'arabic'
13
+ gem "arabic"
11
14
  ```
12
15
 
13
16
  And then execute:
@@ -22,22 +25,62 @@ Or install it yourself as:
22
25
 
23
26
  ```ruby
24
27
  require "arabic"
25
- ```
26
-
27
- And then
28
28
 
29
- ```ruby
29
+ # Default Arabic transliteration
30
30
  Arabic.transliterate("العربية")
31
- ```
32
- or
31
+ # => "alerbyt"
33
32
 
34
- ```ruby
33
+ # Short alias .t
35
34
  Arabic.t("العربية")
35
+ # => "alerbyt"
36
+
37
+ # Urdu scheme
38
+ Arabic.t("اردو", :urdu)
39
+ # => "ardv"
40
+
41
+ # ISO 233 scheme
42
+ Arabic.t("اردو", :iso233)
43
+ # => "ʾrdw"
44
+
45
+ # Persian scheme
46
+ Arabic.t("فارسی", :persian)
47
+ # => "farsy"
48
+
49
+ # Numbers and punctuation
50
+ Arabic.t("٠١٢٣٤٥٦٧۸٩")
51
+ # => "0123456789"
52
+ ```
53
+
54
+ ### Command Line Interface (CLI)
55
+
56
+ You can also use `arabic` directly from the command line:
57
+
58
+ ```bash
59
+ # Direct argument
60
+ $ arabic "العربية"
61
+ alerbyt
62
+
63
+ # Piped input (STDIN)
64
+ $ echo "العربية" | arabic
65
+ alerbyt
66
+
67
+ # File input
68
+ $ arabic text.txt
69
+
70
+ # Select transliteration scheme (default, urdu, iso233, persian)
71
+ $ arabic -s urdu "اردو"
72
+ ardv
73
+
74
+ $ arabic -s iso233 "كتاب"
75
+ ktʾb
76
+
77
+ $ arabic -s persian "فارسی"
78
+ farsy
36
79
  ```
37
80
 
38
81
  ## Development
39
82
 
40
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run tests and code style checks (RuboCop). You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
84
 
42
85
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
86
 
@@ -51,4 +94,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
51
94
 
52
95
  ## Code of Conduct
53
96
 
54
- Everyone interacting in the Arabic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/arabic/blob/master/CODE_OF_CONDUCT.md).
97
+ Everyone interacting in the Arabic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/arabic/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
7
10
  t.test_files = FileList["test/**/*_test.rb"]
8
11
  end
9
12
 
10
- task :default => :test
13
+ RuboCop::RakeTask.new(:rubocop)
14
+
15
+ task default: %i[test rubocop]
data/arabic.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
 
4
6
  require "arabic/version"
@@ -13,15 +15,27 @@ Gem::Specification.new do |spec|
13
15
  spec.description = "Converts Arabic text to the Roman (Latin) script"
14
16
  spec.homepage = "https://github.com/rovetz/arabic"
15
17
  spec.license = "MIT"
18
+ spec.required_ruby_version = ">= 3.3.0"
19
+
20
+ spec.metadata["source_code_uri"] = "https://github.com/rovetz/arabic"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rovetz/arabic/blob/main/CHANGELOG.md"
22
+ spec.metadata["bug_tracker_uri"] = "https://github.com/rovetz/arabic/issues"
23
+ spec.metadata["rubygems_mfa_required"] = "true"
16
24
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github Gemfile])
29
+ end
19
30
  end
20
31
  spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.executables = ["arabic"]
22
33
  spec.require_paths = ["lib"]
23
34
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_development_dependency "irb"
36
+ spec.add_development_dependency "minitest", ">= 5.25"
37
+ spec.add_development_dependency "rake", ">= 13.2"
38
+ spec.add_development_dependency "rdoc"
39
+ spec.add_development_dependency "rubocop", ">= 1.64"
40
+ spec.add_development_dependency "simplecov", ">= 0.22"
27
41
  end
data/exe/arabic ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "optparse"
5
+ require "arabic"
6
+
7
+ scheme = nil
8
+
9
+ parser = OptionParser.new do |opts|
10
+ opts.banner = "Usage: arabic [options] [text | file...]"
11
+ opts.separator ""
12
+ opts.separator "Transliterate Arabic script to Roman script."
13
+ opts.separator ""
14
+ opts.separator "Examples:"
15
+ opts.separator " arabic 'مرحبا'"
16
+ opts.separator " echo 'مرحبا' | arabic"
17
+ opts.separator " arabic text.txt"
18
+ opts.separator " arabic -s urdu 'اردو'"
19
+ opts.separator " arabic -s iso233 'كتاب'"
20
+ opts.separator " arabic -s persian 'فارسی'"
21
+ opts.separator ""
22
+ opts.separator "Options:"
23
+
24
+ opts.on("-s", "--scheme SCHEME", %w[default urdu iso233 persian],
25
+ "Transliteration scheme (default, urdu, iso233, persian)") do |s|
26
+ scheme = s == "default" ? nil : s.to_sym
27
+ end
28
+
29
+ opts.on("-v", "--version", "Show version") do
30
+ puts "arabic #{Arabic::VERSION}"
31
+ exit
32
+ end
33
+
34
+ opts.on("-h", "--help", "Show this help message") do
35
+ puts opts
36
+ exit
37
+ end
38
+ end
39
+
40
+ parser.parse!
41
+
42
+ transliterate = lambda do |text|
43
+ Arabic.transliterate(text, scheme || :arabic)
44
+ end
45
+
46
+ if ARGV.empty?
47
+ if $stdin.tty?
48
+ puts parser
49
+ exit 1
50
+ else
51
+ $stdin.each_line do |line|
52
+ puts transliterate.call(line.chomp)
53
+ end
54
+ end
55
+ else
56
+ ARGV.each do |arg|
57
+ if File.file?(arg)
58
+ File.foreach(arg) do |line|
59
+ puts transliterate.call(line.chomp)
60
+ end
61
+ else
62
+ puts transliterate.call(arg)
63
+ end
64
+ end
65
+ end
data/lib/arabic/iso233.rb CHANGED
@@ -1,53 +1,61 @@
1
- module Iso233
2
- CHARACTER_TABLE = {
3
- # Numbers
4
- "٠" => "0",
5
- "١" => "1",
6
- "٢" => "2",
7
- "٣" => "3",
8
- "٤" => "4",
9
- "٥" => "5",
10
- "٦" => "6",
11
- "٧" => "7",
12
- "۸" => "8",
13
- "٩" => "9",
14
- # Punctuation
15
- "،" => ",",
16
- "؛" => ";",
17
- "؟" => "?",
18
- # Consonants (Letters of the Alphabet)
19
- "ء" => "ˌ",
20
- "ٔ◌" => "ˈ",
21
- "ٕ◌" => "",
22
- "ا" => "ʾ",
23
- "ب" => "b",
24
- "ت" => "t",
25
- "ث" => "",
26
- "ج" => "ǧ",
27
- "ح" => "",
28
- "خ" => "",
29
- "د" => "d",
30
- "ذ" => "",
31
- "ر" => "r",
32
- "ز" => "z",
33
- "س" => "s",
34
- "ش" => "š",
35
- "ص" => "",
36
- "ض" => "",
37
- "ط" => "",
38
- "ظ" => "",
39
- "ع" => "ʿ",
40
- "غ" => "ġ",
41
- "ف" => "f",
42
- "ق" => "q",
43
- "ك" => "k",
44
- "ل" => "l",
45
- "م" => "m",
46
- "ن" => "n",
47
- "ه" => "h",
48
- "ة" => "",
49
- "و" => "w",
50
- "ي" => "y",
51
- "ى" => ""
52
- }
1
+ # frozen_string_literal: true
2
+
3
+ module Arabic
4
+ module Iso233
5
+ CHARACTER_TABLE = {
6
+ # Numbers
7
+ "٠" => "0",
8
+ "١" => "1",
9
+ "٢" => "2",
10
+ "٣" => "3",
11
+ "٤" => "4",
12
+ "٥" => "5",
13
+ "٦" => "6",
14
+ "٧" => "7",
15
+ "۸" => "8",
16
+ "٩" => "9",
17
+ # Punctuation
18
+ "،" => ",",
19
+ "؛" => ";",
20
+ "؟" => "?",
21
+ # Consonants (Letters of the Alphabet)
22
+ "ء" => "ˌ",
23
+ "ٔ" => "ˈ",
24
+ "ٕ" => "",
25
+ "ا" => "ʾ",
26
+ "ب" => "b",
27
+ "ت" => "t",
28
+ "ث" => "",
29
+ "ج" => "ǧ",
30
+ "ح" => "",
31
+ "خ" => "",
32
+ "د" => "d",
33
+ "ذ" => "",
34
+ "ر" => "r",
35
+ "ز" => "z",
36
+ "س" => "s",
37
+ "ش" => "š",
38
+ "ص" => "",
39
+ "ض" => "",
40
+ "ط" => "",
41
+ "ظ" => "",
42
+ "ع" => "ʿ",
43
+ "غ" => "ġ",
44
+ "ف" => "f",
45
+ "ق" => "q",
46
+ "ك" => "k",
47
+ "ل" => "l",
48
+ "م" => "m",
49
+ "ن" => "n",
50
+ "ه" => "h",
51
+ "ة" => "",
52
+ "و" => "w",
53
+ "ي" => "y",
54
+ "ى" => "ỳ"
55
+ }.freeze
56
+
57
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
58
+ end
53
59
  end
60
+
61
+ Iso233 = Arabic::Iso233 unless defined?(Iso233)
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arabic
4
+ module Persian
5
+ CHARACTER_TABLE = {
6
+ # Numbers (Persian / Eastern Arabic-Indic digits)
7
+ "۰" => "0",
8
+ "۱" => "1",
9
+ "۲" => "2",
10
+ "۳" => "3",
11
+ "۴" => "4",
12
+ "۵" => "5",
13
+ "۶" => "6",
14
+ "۷" => "7",
15
+ "۸" => "8",
16
+ "۹" => "9",
17
+ # Punctuation
18
+ "،" => ",",
19
+ "؛" => ";",
20
+ "؟" => "?",
21
+ # Consonants (Persian alphabet - 32 letters)
22
+ "ا" => "a",
23
+ "آ" => "aa",
24
+ "ب" => "b",
25
+ "پ" => "p",
26
+ "ت" => "t",
27
+ "ث" => "s",
28
+ "ج" => "j",
29
+ "چ" => "ch",
30
+ "ح" => "h",
31
+ "خ" => "kh",
32
+ "د" => "d",
33
+ "ذ" => "z",
34
+ "ر" => "r",
35
+ "ز" => "z",
36
+ "ژ" => "zh",
37
+ "س" => "s",
38
+ "ش" => "sh",
39
+ "ص" => "s",
40
+ "ض" => "z",
41
+ "ط" => "t",
42
+ "ظ" => "z",
43
+ "ع" => "‘",
44
+ "غ" => "gh",
45
+ "ف" => "f",
46
+ "ق" => "q",
47
+ "ک" => "k",
48
+ "ك" => "k",
49
+ "گ" => "g",
50
+ "ل" => "l",
51
+ "م" => "m",
52
+ "ن" => "n",
53
+ "و" => "v",
54
+ "ه" => "h",
55
+ "ی" => "y",
56
+ "ي" => "y",
57
+ "ء" => "'",
58
+ "ة" => "t",
59
+ "أ" => "a",
60
+ "إ" => "e",
61
+ "ؤ" => "o",
62
+ "ئ" => "y",
63
+ "ى" => "a"
64
+ }.freeze
65
+
66
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
67
+ end
68
+ end
69
+
70
+ Persian = Arabic::Persian unless defined?(Persian)
data/lib/arabic/urdu.rb CHANGED
@@ -1,68 +1,76 @@
1
- module Urdu
2
- CHARACTER_TABLE = {
3
- # Numbers
4
- "۰" => "0",
5
- "۱" => "1",
6
- "۲" => "2",
7
- "۳" => "3",
8
- "۴" => "4",
9
- "۵" => "5",
10
- "۶" => "6",
11
- "۷" => "7",
12
- "۸" => "8",
13
- "۹" => "9",
14
- # Punctuation
15
- "،" => ",",
16
- "؛" => ";",
17
- "؟" => "?",
18
- # Consonants (Letters of the Alphabet)
19
- "ا" => "a",
20
- "آ" => "aa",
21
- "ب" => "b",
22
- "پ" => "p",
23
- "ت" => "t",
24
- "ٹ" => "t",
25
- "ث" => "s",
26
- "ج" => "j",
27
- "چ" => "c",
28
- "ح" => "h",
29
- "خ" => "kh",
30
- "د" => "d",
31
- "ڈ" => "d",
32
- "ذ" => "z",
33
- "ر" => "r",
34
- "ڑ" => "r",
35
- "ز" => "z",
36
- "ژ" => "zh",
37
- "س" => "s",
38
- "ش" => "sh",
39
- "ص" => "s",
40
- "ض" => "z",
41
- "ط" => "t",
42
- "ظ" => "z",
43
- "ع" => "",
44
- "غ" => "gh",
45
- "ف" => "f",
46
- "ق" => "q",
47
- "ک" => "k",
48
- "گ" => "g",
49
- "ل" => "l",
50
- "م" => "m",
51
- "ن" => "n",
52
- "ں" => "n",
53
- "و" => "v",
54
- "ه" => "h",
55
- "" => "h",
56
- "" => "h",
57
- "ہ" => "h",
58
- "ھ" => "h",
59
- "ء" => "'",
60
- "ة" => "t",
61
- "ی" => "i",
62
- "ى" => "y",
63
- "ئ" => "y",
64
- "ے" => "e",
65
- "ۂ" => "a",
66
- "ؤ" => "o"
67
- }
1
+ # frozen_string_literal: true
2
+
3
+ module Arabic
4
+ module Urdu
5
+ CHARACTER_TABLE = {
6
+ # Numbers
7
+ "۰" => "0",
8
+ "۱" => "1",
9
+ "۲" => "2",
10
+ "۳" => "3",
11
+ "۴" => "4",
12
+ "۵" => "5",
13
+ "۶" => "6",
14
+ "۷" => "7",
15
+ "۸" => "8",
16
+ "۹" => "9",
17
+ # Punctuation
18
+ "،" => ",",
19
+ "؛" => ";",
20
+ "؟" => "?",
21
+ # Consonants (Letters of the Alphabet)
22
+ "ا" => "a",
23
+ "آ" => "aa",
24
+ "ب" => "b",
25
+ "پ" => "p",
26
+ "ت" => "t",
27
+ "ٹ" => "t",
28
+ "ث" => "s",
29
+ "ج" => "j",
30
+ "چ" => "c",
31
+ "ح" => "h",
32
+ "خ" => "kh",
33
+ "د" => "d",
34
+ "ڈ" => "d",
35
+ "ذ" => "z",
36
+ "ر" => "r",
37
+ "ڑ" => "r",
38
+ "ز" => "z",
39
+ "ژ" => "zh",
40
+ "س" => "s",
41
+ "ش" => "sh",
42
+ "ص" => "s",
43
+ "ض" => "z",
44
+ "ط" => "t",
45
+ "ظ" => "z",
46
+ "ع" => "",
47
+ "غ" => "gh",
48
+ "ف" => "f",
49
+ "ق" => "q",
50
+ "ک" => "k",
51
+ "گ" => "g",
52
+ "ل" => "l",
53
+ "م" => "m",
54
+ "ن" => "n",
55
+ "ں" => "n",
56
+ "و" => "v",
57
+ "ه" => "h",
58
+ "" => "h",
59
+ "" => "h",
60
+ "ہ" => "h",
61
+ "ھ" => "h",
62
+ "ء" => "'",
63
+ "ة" => "t",
64
+ "ی" => "i",
65
+ "ى" => "y",
66
+ "ئ" => "y",
67
+ "ے" => "e",
68
+ "ۂ" => "a",
69
+ "ؤ" => "o"
70
+ }.freeze
71
+
72
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
73
+ end
68
74
  end
75
+
76
+ Urdu = Arabic::Urdu unless defined?(Urdu)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arabic
2
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
3
5
  end
data/lib/arabic.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "arabic/version"
2
4
  require "arabic/urdu"
3
5
  require "arabic/iso233"
6
+ require "arabic/persian"
4
7
 
5
8
  module Arabic
6
9
  CHARACTER_TABLE = {
@@ -56,19 +59,44 @@ module Arabic
56
59
  "و" => "w",
57
60
  "ى" => "a",
58
61
  "ي" => "y",
59
- "و‎" => "u",
60
62
  # Vowels and Diphthongs
61
- "َ‎" => "a",
62
- "ُ" => "u",
63
- "ِ‎" => "i"
64
- }
63
+ "َ" => "a",
64
+ "ُ" => "u",
65
+ "ِ" => "i"
66
+ }.freeze
67
+
68
+ REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
69
+
70
+ SCHEMES = {
71
+ arabic: [CHARACTER_TABLE, REGEXP].freeze,
72
+ urdu: [Urdu::CHARACTER_TABLE, Urdu::REGEXP].freeze,
73
+ iso233: [Iso233::CHARACTER_TABLE, Iso233::REGEXP].freeze,
74
+ persian: [Persian::CHARACTER_TABLE, Persian::REGEXP].freeze
75
+ }.freeze
65
76
 
66
77
  class << self
67
- def transliterate(string="", to=:arabic)
68
- character_table = Module.const_get(to.to_s.capitalize)::CHARACTER_TABLE
69
- string.to_s.gsub(/#{Regexp.union(character_table.keys).source}/i, character_table)
78
+ # Transliterates Arabic, Urdu, Persian, and related text into Latin script.
79
+ #
80
+ # @param string [String, #to_s] The text to transliterate.
81
+ # @param to [Symbol, String] The transliteration scheme (:arabic, :urdu, :iso233, :persian).
82
+ # @return [String] The transliterated Latin script string.
83
+ # @raise [ArgumentError] If the given transliteration scheme is unknown.
84
+ #
85
+ # @example Default Arabic transliteration
86
+ # Arabic.transliterate("العربية") #=> "alerbyt"
87
+ #
88
+ # @example Urdu transliteration using short alias .t
89
+ # Arabic.t("اردو", :urdu) #=> "ardv"
90
+ def transliterate(string = "", to = :arabic)
91
+ scheme = SCHEMES[to.to_s.downcase.to_sym]
92
+ unless scheme
93
+ available = SCHEMES.keys.map(&:inspect).join(", ")
94
+ raise ArgumentError, "Unknown transliteration scheme: #{to.inspect}. Available schemes: #{available}"
95
+ end
96
+
97
+ table, regexp = scheme
98
+ string.to_s.gsub(regexp, table)
70
99
  end
71
- alias_method :t, :transliterate
100
+ alias t transliterate
72
101
  end
73
-
74
102
  end
metadata CHANGED
@@ -1,84 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arabic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rovetz
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2018-09-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: irb
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.16'
18
+ version: '0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '1.16'
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.25'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5.25'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: rake
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
- - - "~>"
44
+ - - ">="
32
45
  - !ruby/object:Gem::Version
33
- version: '10.0'
46
+ version: '13.2'
34
47
  type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
- - - "~>"
51
+ - - ">="
39
52
  - !ruby/object:Gem::Version
40
- version: '10.0'
53
+ version: '13.2'
41
54
  - !ruby/object:Gem::Dependency
42
- name: minitest
55
+ name: rdoc
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
- - - "~>"
72
+ - - ">="
46
73
  - !ruby/object:Gem::Version
47
- version: '5.0'
74
+ version: '1.64'
48
75
  type: :development
49
76
  prerelease: false
50
77
  version_requirements: !ruby/object:Gem::Requirement
51
78
  requirements:
52
- - - "~>"
79
+ - - ">="
53
80
  - !ruby/object:Gem::Version
54
- version: '5.0'
81
+ version: '1.64'
82
+ - !ruby/object:Gem::Dependency
83
+ name: simplecov
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0.22'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0.22'
55
96
  description: Converts Arabic text to the Roman (Latin) script
56
97
  email:
57
98
  - zakbox@gmail.com
58
- executables: []
99
+ executables:
100
+ - arabic
59
101
  extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
62
- - ".gitignore"
63
- - ".travis.yml"
104
+ - ".rubocop.yml"
105
+ - CHANGELOG.md
64
106
  - CODE_OF_CONDUCT.md
65
- - Gemfile
66
- - Gemfile.lock
67
107
  - LICENSE.txt
68
108
  - README.md
69
109
  - Rakefile
70
110
  - arabic.gemspec
71
- - bin/console
72
- - bin/setup
111
+ - exe/arabic
73
112
  - lib/arabic.rb
74
113
  - lib/arabic/iso233.rb
114
+ - lib/arabic/persian.rb
75
115
  - lib/arabic/urdu.rb
76
116
  - lib/arabic/version.rb
77
117
  homepage: https://github.com/rovetz/arabic
78
118
  licenses:
79
119
  - MIT
80
- metadata: {}
81
- post_install_message:
120
+ metadata:
121
+ source_code_uri: https://github.com/rovetz/arabic
122
+ changelog_uri: https://github.com/rovetz/arabic/blob/main/CHANGELOG.md
123
+ bug_tracker_uri: https://github.com/rovetz/arabic/issues
124
+ rubygems_mfa_required: 'true'
82
125
  rdoc_options: []
83
126
  require_paths:
84
127
  - lib
@@ -86,16 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
129
  requirements:
87
130
  - - ">="
88
131
  - !ruby/object:Gem::Version
89
- version: '0'
132
+ version: 3.3.0
90
133
  required_rubygems_version: !ruby/object:Gem::Requirement
91
134
  requirements:
92
135
  - - ">="
93
136
  - !ruby/object:Gem::Version
94
137
  version: '0'
95
138
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.7
98
- signing_key:
139
+ rubygems_version: 4.0.20
99
140
  specification_version: 4
100
141
  summary: Romanization (transliteration) of Arabic
101
142
  test_files: []
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in arabic.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- arabic (0.1.6)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.11.3)
10
- rake (10.5.0)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- arabic!
17
- bundler (~> 1.16)
18
- minitest (~> 5.0)
19
- rake (~> 10.0)
20
-
21
- BUNDLED WITH
22
- 1.16.2
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "arabic"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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