class Rus3::Char

Constants

LITERAL_NEWLINE
LITERAL_PREFIX
LITERAL_SPACE

Attributes

codepoint[R]
encoding[R]

Public Class Methods

alphabetic?(char) click to toggle source
# File lib/rus3/char.rb, line 10
def alphabetic?(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  /[A-Za-z]/ === char.to_s
end
char_to_integer(char) click to toggle source
# File lib/rus3/char.rb, line 35
def char_to_integer(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  char.codepoint
end
compare_chars(char1, char2, comp_op, ignore_case: false) click to toggle source
# File lib/rus3/char.rb, line 54
def compare_chars(char1, char2, comp_op, ignore_case: false)
  if !char1.instance_of?(self)
    raise CharRequiredError, char1
  elsif !char2.instance_of?(self)
    raise CharRequiredError, char2
  end

  if ignore_case
    char1 = downcase(char1)
    char2 = downcase(char2)
  end
  char1.send(comp_op, char2)
end
downcase(char) click to toggle source
# File lib/rus3/char.rb, line 49
def downcase(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  self.new(char.to_s.downcase)
end
integer_to_char(n, encoding: Encoding::UTF_8) click to toggle source
# File lib/rus3/char.rb, line 40
def integer_to_char(n, encoding: Encoding::UTF_8)
  self.new(n.chr(encoding))
end
lower_case?(char) click to toggle source
# File lib/rus3/char.rb, line 30
def lower_case?(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  /[a-z]/ === char.to_s
end
new(str) click to toggle source
# File lib/rus3/char.rb, line 77
def initialize(str)
  @char = str[0].dup.freeze
  @encoding = str.encoding
  @codepoint = @char.ord
end
numeric?(char) click to toggle source
# File lib/rus3/char.rb, line 15
def numeric?(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  /[0-9]/ === char.to_s
end
upcase(char) click to toggle source
# File lib/rus3/char.rb, line 44
def upcase(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  self.new(char.to_s.upcase)
end
upper_case?(char) click to toggle source
# File lib/rus3/char.rb, line 25
def upper_case?(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  /[A-Z]/ === char.to_s
end
whitespace?(char) click to toggle source
# File lib/rus3/char.rb, line 20
def whitespace?(char)
  raise CharRequiredError, char unless char.instance_of?(Char)
  /[\s]/ === char.to_s
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/rus3/char.rb, line 87
def <=>(other)
  raise CharRequiredError, other unless other.instance_of?(Char)
  @codepoint <=> other.codepoint
end
==(other) click to toggle source
# File lib/rus3/char.rb, line 83
def ==(other)
  other.instance_of?(Char) and to_s == other.to_s
end
to_literal() click to toggle source
# File lib/rus3/char.rb, line 92
def to_literal
  LITERAL_PREFIX + @char
end
to_s() click to toggle source
# File lib/rus3/char.rb, line 96
def to_s
  @char
end