Class: LexoRanker::Ranker::CharacterSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/lexoranker/ranker.rb

Defined Under Namespace

Classes: CharNotInCharacterSpaceError, EmptyCharacterSpaceError, IndexOutOfCharacterSpaceError

Constant Summary collapse

CHARACTERS =
[*"0".."9", *"A".."Z", *"a".."z"].sort.freeze

Class Method Summary collapse

Class Method Details

.chr(ord) ⇒ String

Returns:

  • (String)


255
256
257
# File 'lib/lexoranker/ranker.rb', line 255

def chr(ord)
  CHARACTERS[ord] || (raise IndexOutOfCharacterSpaceError, "Index: #{ord} outside current character space")
end

.maxString

Returns:

  • (String)


267
268
269
# File 'lib/lexoranker/ranker.rb', line 267

def max
  CHARACTERS.last || (raise EmptyCharacterSpaceError, "Character Space is empty")
end

.minString

Returns:

  • (String)


261
262
263
# File 'lib/lexoranker/ranker.rb', line 261

def min
  CHARACTERS.first || (raise EmptyCharacterSpaceError, "Character Space is empty")
end

.ord(char) ⇒ Integer

Returns:

  • (Integer)


248
249
250
251
# File 'lib/lexoranker/ranker.rb', line 248

def ord(char)
  CHARACTERS.index(char) || (raise CharNotInCharacterSpaceError,
    "Character: #{char} not found in current character space")
end

.sizeObject



271
272
273
# File 'lib/lexoranker/ranker.rb', line 271

def size
  CHARACTERS.size
end