Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/c12-commons/string.rb

Constant Summary collapse

GEO =

Translation between legacy character sets.

'ÀÁÂÃÄÅÆÈÉÊËÌÍÏÐÑÒÓÔÖ×ØÙÚÛÜÝÞßàáãä#'
KA =
'აბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰ№'
LAT =
'abgdevzTiklmnopJrstufqRySCcZwWxjh#'

Instance Method Summary collapse

Instance Method Details

#next_numberObject

Generates next numeric value from this string.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/c12-commons/string.rb', line 5

def next_number
  index = self.index(/[0-9]*$/)
  if index
    pref = self[0, index]
    suff = self[index, self.length].to_i + 1
    lnth = self.length - pref.length
    %Q{#{pref}#{("%0#{lnth}d" % suff)}}
  else
    "#{self}1"
  end
end

#to_geoObject



40
41
42
# File 'lib/c12-commons/string.rb', line 40

def to_geo
  self.translate(KA, GEO)
end

#to_ka(deep = false) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/c12-commons/string.rb', line 32

def to_ka(deep = false)
  if deep
    self.translate("#{GEO}#{LAT}", "#{KA}#{KA}")
  else
    self.translate(GEO, KA)
  end
end

#to_latObject



44
45
46
# File 'lib/c12-commons/string.rb', line 44

def to_lat
  self.translate("#{GEO}#{KA}", "#{LAT}#{LAT}")
end

#translate(from, to) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/c12-commons/string.rb', line 23

def translate(from, to)
  txt = ""
  self.split('').each do |c|
    indx = from.index(c)
    txt += indx ? to[indx] : c
  end
  txt
end