Class: Irc::Casemap
- Inherits:
-
Object
- Object
- Irc::Casemap
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/irc.rb
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
- @@casemaps =
{}
Class Method Summary (collapse)
-
+ (Object) get(name)
Returns the Casemap with the given name.
Instance Method Summary (collapse)
-
- (Object) ==(arg)
Two Casemaps are equal if they have the same upper and lower ranges.
-
- (Casemap) initialize(name, upper, lower)
constructor
Create a new casemap with name name, uppercase characters upper and lowercase characters lower.
-
- (Object) inspect
A Casemap is represented by its lower/upper mappings.
-
- (Object) lower
Retrieve the 'lowercase characters' of this Casemap.
-
- (Object) must_be(arg)
Give a warning if arg and self are not the same Casemap.
-
- (Object) to_irc_casemap
Return a Casemap based on the receiver.
-
- (Object) to_s
As a String we return our name.
-
- (Object) upper
Retrieve the 'uppercase characters' of this Casemap.
Constructor Details
- (Casemap) initialize(name, upper, lower)
Create a new casemap with name name, uppercase characters upper and lowercase characters lower
74 75 76 77 78 79 80 81 82 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 74 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
+ (Object) get(name)
Returns the Casemap with the given name
86 87 88 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 86 def Casemap.get(name) @@casemaps[name.to_sym][:casemap] end |
Instance Method Details
- (Object) ==(arg)
Two Casemaps are equal if they have the same upper and lower ranges
122 123 124 125 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 122 def ==(arg) other = arg.to_irc_casemap return self.upper == other.upper && self.lower == other.lower end |
- (Object) inspect
A Casemap is represented by its lower/upper mappings
110 111 112 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 110 def inspect self.__to_s__[0..-2] + " #{upper.inspect} ~(#{self})~ #{lower.inspect}>" end |
- (Object) lower
Retrieve the 'lowercase characters' of this Casemap
98 99 100 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 98 def lower @@casemaps[@key][:lower] end |
- (Object) must_be(arg)
Give a warning if arg and self are not the same Casemap
129 130 131 132 133 134 135 136 137 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 129 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 |
- (Object) to_irc_casemap
Return a Casemap based on the receiver
104 105 106 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 104 def to_irc_casemap self end |
- (Object) to_s
As a String we return our name
116 117 118 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 116 def to_s @key.to_s end |
- (Object) upper
Retrieve the 'uppercase characters' of this Casemap
92 93 94 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 92 def upper @@casemaps[@key][:upper] end |