Class: Persian::Unicode

Inherits:
Object
  • Object
show all
Defined in:
lib/persian/unicode.rb

Overview

Persian Unicode class

Class Method Summary collapse

Class Method Details

.codepoint_to_char(char) ⇒ Object


7
8
9
10
# File 'lib/persian/unicode.rb', line 7

def self.codepoint_to_char(char)
  return [char].pack('U') if char.is_a? Fixnum
  [char.hex].pack('U')
end

.lre(text) ⇒ Object

Return text between LETF-TO-RIGHT EMBEDDING(U+202A) and Pop Directional Format(U+202C)


21
22
23
24
25
26
# File 'lib/persian/unicode.rb', line 21

def self.lre(text)
  rle_tag = 0x202A
  pop_tag = 0x202C

  codepoint_to_char(rle_tag) + text + codepoint_to_char(pop_tag)
end

.lro(text) ⇒ Object


35
36
37
38
39
40
# File 'lib/persian/unicode.rb', line 35

def self.lro(text)
  rlo_tag = 0x202D
  pop_tag = 0x202C

  codepoint_to_char(rlo_tag) + text + codepoint_to_char(pop_tag)
end

.rle(text) ⇒ Object

Return text between RIGHT-TO-LETF EMBEDDING(U+202B) and Pop Directional Format(U+202C)


13
14
15
16
17
18
# File 'lib/persian/unicode.rb', line 13

def self.rle(text)
  lre_tag = 0x202B
  pop_tag = 0x202C

  codepoint_to_char(lre_tag) + text + codepoint_to_char(pop_tag)
end

.rlo(text) ⇒ Object


28
29
30
31
32
33
# File 'lib/persian/unicode.rb', line 28

def self.rlo(text)
  lro_tag = 0x202E
  pop_tag = 0x202C

  codepoint_to_char(lro_tag) + text + codepoint_to_char(pop_tag)
end