Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rupircd/charcode.rb

Constant Summary collapse

Flag =
{
  NKF::UTF8 => "-W", NKF::SJIS => "-S",
  NKF::JIS => "-J", NKF::EUC => "-E",
  "Shift_JIS" => "-S", "UTF-8" => "-W",
  "ISO-2022-JP" => "-J", "EUC-JP" => "-E"
}

Instance Method Summary collapse

Instance Method Details

#encode(code) ⇒ Object



31
32
33
34
# File 'lib/rupircd/charcode.rb', line 31

def encode(code)
  flag = Flag[NKF.guess self]
  NKF.nkf("#{flag} #{Flag[code].downcase}", self)
end

#encode!(code) ⇒ Object



37
38
39
# File 'lib/rupircd/charcode.rb', line 37

def encode!(code)
  replace encode(code)
end

#tojisObject



21
22
23
24
25
26
27
28
# File 'lib/rupircd/charcode.rb', line 21

def tojis
  if RUBY_VERSION < "1.9"
    flag = Flag[NKF.guess(self)]
    NKF.nkf("#{flag} -j", self)
  else
    self.encode("ISO-2022-JP")
  end
end

#tojis!Object



55
56
57
# File 'lib/rupircd/charcode.rb', line 55

def tojis!
  replace(tojis)
end

#toutf8Object



42
43
44
45
46
47
48
49
# File 'lib/rupircd/charcode.rb', line 42

def toutf8
  if RUBY_VERSION < "1.9"
    flag = Flag[NKF.guess(self)]
    NKF.nkf("#{flag} -w8", self)[3..-1]
  else
    self.encode("UTF-8")
  end
end

#toutf8!Object



51
52
53
# File 'lib/rupircd/charcode.rb', line 51

def toutf8!
  replace(toutf8)
end