Module: Rtl
- Defined in:
- lib/rtl/core.rb,
lib/rtl/version.rb
Constant Summary collapse
- FULL_NAMES =
Formal full names for RTL languages.
["Adlam", "Arabic", "Arabic (Nastaliq variant)", "Imperial Aramaic", "Avestan", "Cypriot", "Egyptian demotic", "Egyptian hieratic", "Hatran", "Hebrew", "Old Hungarian (Hungarian Runic)", "Indus (Harappan)", "Kharoshthi", "Lydian", "Mandaic, Mandaean", "Manichaean", "Mende Kikakui", "Meroitic Cursive", "Meroitic Hieroglyphs", "Old North Arabian (Ancient North Arabian)", "Nabataean", "N’Ko", "Old Turkic, Orkhon Runic", "Palmyrene", "Inscriptional Pahlavi", "Psalter Pahlavi", "Book Pahlavi", "Phoenician", "Inscriptional Parthian", "Samaritan", "Old South Arabian", "Syriac", "Syriac (Estrangelo variant)", "Syriac (Western variant)", "Syriac (Eastern variant)", "Thaana", "Woleai"]
- ISO_CODES =
ISO 639 codes for RTL languages. If a language has 639-1 and 639-2 codes, both are included.
["ar", "ara", "arc", "ae", "ave", "egy", "he", "heb", "nqo", "pal", "phn", "sam", "syc", "syr"]
- ISO_LONG_CODES =
ISO 15924 codes for RTL languages.
['Adlm', 'Arab', 'Aran', 'Armi', 'Avst', 'Cprt', 'Egyd', 'Egyh', 'Hatr', 'Hebr', 'Hung', 'Inds', 'Khar', 'Lydi', 'Mand', 'Mani', 'Mend', 'Merc', 'Mero', 'Narb', 'Nbat', 'Nkoo', 'Orkh', 'Palm', 'Phli', 'Phlp', 'Phlv', 'Phnx', 'Prti', 'Samr', 'Sarb', 'Syrc', 'Syre', 'Syrj', 'Syrn', 'Thaa', 'Wole']
- ISO_NUMBERS =
ISO 15924 numbers for RTL languages.
['166', '160', '161', '124', '134', '403', '070', '060', '127', '125', '176', '610', '305', '116', '140', '139', '438', '101', '100', '106', '159', '165', '175', '126', '131', '132', '133', '115', '130', '123', '105', '135', '138', '137', '136', '170', '480']
- UNICODE_ALIASES =
Unicode alias names for RTL languages. Not all ISO languages has this alias.
["Adlam", "Arabic", "Imperial Aramaic", "Avestan", "Cypriot", "Hatran", "Hebrew", "Old Hungarian", "Kharoshthi", "Lydian", "Mandaic", "Manichaean", "Mende Kikakui", "Meroitic Cursive", "Meroitic Hieroglyphs", "Old North Arabian", "Nabataean", "NKo", "Old Turkic", "Palmyrene", "Inscriptional Pahlavi", "Psalter Pahlavi", "Phoenician", "Inscriptional Parthian", "Samaritan", "Old South Arabian", "Syriac", "Thaana"]
- VERSION =
"0.1.0"
Class Method Summary collapse
- .all(lang) ⇒ Object
- .full_names(lang) ⇒ Object
- .iso_codes(lang) ⇒ Object
- .iso_long_codes(lang) ⇒ Object
- .iso_numbers(lang) ⇒ Object
-
.rtl?(language, scheme = :iso_code) ⇒ Boolean
Query whether a language is rtl or not.
-
.rtl_languages(scheme = :iso_code) ⇒ Object
Get a list of languages by scheme.
- .unicode_aliases(lang) ⇒ Object
Class Method Details
.all(lang) ⇒ Object
95 96 97 98 |
# File 'lib/rtl/core.rb', line 95 def self.all lang iso_codes(lang) || iso_long_codes(lang) || iso_numbers(lang) || full_names(lang) || unicode_aliases(lang) end |
.full_names(lang) ⇒ Object
87 88 89 |
# File 'lib/rtl/core.rb', line 87 def self.full_names lang FULL_NAMES.map(&:capitalize).include? lang.capitalize end |
.iso_codes(lang) ⇒ Object
75 76 77 |
# File 'lib/rtl/core.rb', line 75 def self.iso_codes lang ISO_CODES.include? lang.downcase end |
.iso_long_codes(lang) ⇒ Object
79 80 81 |
# File 'lib/rtl/core.rb', line 79 def self.iso_long_codes lang ISO_LONG_CODES.include? lang.capitalize end |
.iso_numbers(lang) ⇒ Object
83 84 85 |
# File 'lib/rtl/core.rb', line 83 def self.iso_numbers lang ISO_NUMBERS.include? lang end |
.rtl?(language, scheme = :iso_code) ⇒ Boolean
Query whether a language is rtl or not.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rtl/core.rb', line 43 def self.rtl? language, scheme = :iso_code sch = scheme.to_sym l = language.to_s.strip case sch when :iso_code self.iso_codes l when :iso_long_code self.iso_long_codes l when :iso_number self.iso_numbers l when :unicode_alias self.unicode_aliases l when :full_name self.full_names l when :all all l else raise ArgumentError.new "Unknown base value #{base}." end end |
.rtl_languages(scheme = :iso_code) ⇒ Object
Get a list of languages by scheme
66 67 68 69 70 71 |
# File 'lib/rtl/core.rb', line 66 def self.rtl_languages scheme = :iso_code sch = scheme.to_s s = sch.end_with?('s') ? 'ES' : 'S' member = "#{sch.to_s.upcase}#{s}".to_sym self.const_get member end |
.unicode_aliases(lang) ⇒ Object
91 92 93 |
# File 'lib/rtl/core.rb', line 91 def self.unicode_aliases lang UNICODE_ALIASES.map(&:downcase).include? lang.downcase end |