Class: Lapidarist::Level

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/lapidarist/level.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, index:) ⇒ Level

Returns a new instance of Level.



7
8
9
10
# File 'lib/lapidarist/level.rb', line 7

def initialize(name:, index:)
  @name = name
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/lapidarist/level.rb', line 5

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/lapidarist/level.rb', line 5

def name
  @name
end

Class Method Details

.from(name) ⇒ Object



12
13
14
15
# File 'lib/lapidarist/level.rb', line 12

def self.from(name)
  return unless name
  Lapidarist::LEVELS.detect { |l| l.name == name.to_sym }
end

Instance Method Details

#<=>(other) ⇒ Object



21
22
23
24
25
# File 'lib/lapidarist/level.rb', line 21

def <=>(other)
  return 1 if index < other.index
  return 0 if index == other.index
  return -1 if index > other.index
end

#to_sObject



17
18
19
# File 'lib/lapidarist/level.rb', line 17

def to_s
  name.to_s
end