Class: Irc::Casemap
Overview
Due to its Scandinavian origins, IRC has strange case mappings, which consider the characters {}|^
as the uppercase equivalents of # []\~
.
This is however not the same on all IRC servers: some use standard ASCII casemapping, other do not consider ^
as the uppercase of ~
Direct Known Subclasses
Constant Summary collapse
- @@casemaps =
{}
Class Method Summary collapse
-
.get(name) ⇒ Object
Returns the Casemap with the given name.
Instance Method Summary collapse
-
#==(arg) ⇒ Object
Two Casemaps are equal if they have the same upper and lower ranges.
-
#initialize(name, upper, lower) ⇒ Casemap
constructor
Create a new casemap with name name, uppercase characters upper and lowercase characters lower.
-
#inspect ⇒ Object
A Casemap is represented by its lower/upper mappings.
-
#lower ⇒ Object
Retrieve the ‘lowercase characters’ of this Casemap.
-
#must_be(arg) ⇒ Object
Give a warning if arg and self are not the same Casemap.
-
#to_irc_casemap ⇒ Object
Return a Casemap based on the receiver.
-
#to_s ⇒ Object
As a String we return our name.
-
#upper ⇒ Object
Retrieve the ‘uppercase characters’ of this Casemap.
Constructor Details
#initialize(name, upper, lower) ⇒ Casemap
Create a new casemap with name name, uppercase characters upper and lowercase characters lower
57 58 59 60 61 62 63 64 65 |
# File 'lib/rbot/irc.rb', line 57 def initialize(name, upper, lower) @key = name.to_sym raise "Casemap #{name.inspect} already exists!" if @@casemaps.has_key?(@key) @@casemaps[@key] = { :upper => upper, :lower => lower, :casemap => self } end |
Class Method Details
Instance Method Details
#==(arg) ⇒ Object
Two Casemaps are equal if they have the same upper and lower ranges
105 106 107 108 |
# File 'lib/rbot/irc.rb', line 105 def ==(arg) other = arg.to_irc_casemap return self.upper == other.upper && self.lower == other.lower end |
#inspect ⇒ Object
A Casemap is represented by its lower/upper mappings
93 94 95 |
# File 'lib/rbot/irc.rb', line 93 def inspect self.__to_s__[0..-2] + " #{upper.inspect} ~(#{self})~ #{lower.inspect}>" end |
#lower ⇒ Object
Retrieve the ‘lowercase characters’ of this Casemap
81 82 83 |
# File 'lib/rbot/irc.rb', line 81 def lower @@casemaps[@key][:lower] end |
#must_be(arg) ⇒ Object
Give a warning if arg and self are not the same Casemap
112 113 114 115 116 117 118 119 120 |
# File 'lib/rbot/irc.rb', line 112 def must_be(arg) other = arg.to_irc_casemap if self == other return true else warn "Casemap mismatch (#{self.inspect} != #{other.inspect})" return false end end |
#to_irc_casemap ⇒ Object
Return a Casemap based on the receiver
87 88 89 |
# File 'lib/rbot/irc.rb', line 87 def to_irc_casemap self end |
#to_s ⇒ Object
As a String we return our name
99 100 101 |
# File 'lib/rbot/irc.rb', line 99 def to_s @key.to_s end |
#upper ⇒ Object
Retrieve the ‘uppercase characters’ of this Casemap
75 76 77 |
# File 'lib/rbot/irc.rb', line 75 def upper @@casemaps[@key][:upper] end |