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", "Persian", "Kurdish"]
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", "fa", "per", "fas", "ku", "kur"]
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.2.2"

Class Method Summary collapse

Class Method Details

.all(lang) ⇒ Object



100
101
102
103
# File 'lib/rtl/core.rb', line 100

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



92
93
94
# File 'lib/rtl/core.rb', line 92

def self.full_names lang
  FULL_NAMES.map(&:capitalize).include? lang.capitalize
end

.iso_codes(lang) ⇒ Object



80
81
82
# File 'lib/rtl/core.rb', line 80

def self.iso_codes lang
  ISO_CODES.include? lang.downcase
end

.iso_long_codes(lang) ⇒ Object



84
85
86
# File 'lib/rtl/core.rb', line 84

def self.iso_long_codes lang
  ISO_LONG_CODES.include? lang.capitalize
end

.iso_numbers(lang) ⇒ Object



88
89
90
# File 'lib/rtl/core.rb', line 88

def self.iso_numbers lang
  ISO_NUMBERS.include? lang
end

.rtl?(language, scheme = :iso_code) ⇒ Boolean

Query whether a language is rtl or not.

Returns:

  • (Boolean)


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
72
73
74
75
76
# 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.upcase}#{s}".to_sym

  begin
    self.const_get member
  rescue NameError
    raise ArgumentError.new "Unknown Supplied scheme #{sch}."
  end
end

.unicode_aliases(lang) ⇒ Object



96
97
98
# File 'lib/rtl/core.rb', line 96

def self.unicode_aliases lang
  UNICODE_ALIASES.map(&:downcase).include? lang.downcase
end