Class: E4U::Base::Emoji
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ Emoji
Returns a new instance of Emoji.
55
56
57
58
59
60
61
62
|
# File 'lib/e4u/base.rb', line 55
def initialize attributes
@fallback_text = nil
attributes.each do |key, value|
next if key =~ /\A(id|object_id|__(id|send)__)\z/
instance_variable_set("@#{key}", value)
self.class.__send__ :attr_reader, key.to_sym
end
end
|
Instance Attribute Details
#fallback_text ⇒ Object
Returns the value of attribute fallback_text.
64
65
66
|
# File 'lib/e4u/base.rb', line 64
def fallback_text
@fallback_text
end
|
Instance Method Details
#alternate? ⇒ Boolean
69
70
71
|
# File 'lib/e4u/base.rb', line 69
def alternate?
!!(unicode =~ /\A>/)
end
|
#cp932 ⇒ Object
Also known as:
sjis
80
81
82
83
84
85
86
87
|
# File 'lib/e4u/base.rb', line 80
def cp932
return NKF.nkf('-Wsm0x', fallback_text) if fallback?
hex = unicode.sub(/\A[\>\*\+]/, '')
raise if hex.size == 0
chr = hex.split(/\+/, -1).map{ |ch| unicode_to_cp932(ch.hex) }.pack('n*')
chr.force_encoding('CP932') if chr.respond_to? :force_encoding
chr
end
|
#fallback? ⇒ Boolean
65
66
67
|
# File 'lib/e4u/base.rb', line 65
def fallback?
!!fallback_text
end
|
73
74
75
76
77
78
|
# File 'lib/e4u/base.rb', line 73
def utf8
return fallback_text if fallback?
hex = unicode.sub(/\A[\>\*\+]/, '')
raise if hex.size == 0
hex.split(/\+/, -1).map{ |ch| ch.hex }.pack('U*')
end
|