Class: Rubyhexagon::User::Level Private
- Inherits:
-
Object
- Object
- Rubyhexagon::User::Level
- Defined in:
- lib/rubyhexagon/user/level.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class to hold level information.
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
private
Id of level.
-
#name ⇒ String
readonly
private
Name of level.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
private
Comparison method for Level objects.
-
#initialize(level) ⇒ Object
constructor
private
Initializer for Level a user can have.
-
#test ⇒ TrueClass|FalseClass
(also: #unactivated?, #blocked?, #member?, #privileged?, #contributor?, #former_staff?, #janitor?, #mod?, #admin?)
private
Test function for level names.
Constructor Details
#initialize(level) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializer for Level a user can have. This is just to have a more Ruby like interface to it.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubyhexagon/user/level.rb', line 41 def initialize(level) raise ArgumentError, 'No has given.' unless level.is_a?(Hash) raise ArgumentError, 'Hash requires an :id key' if level[:id].nil? unless [0, 10, 20, 30, 32, 33, 34, 40, 50].include?(level[:id]) raise InvalidIDError, "Unknown level ID: #{level[:id]}" end @id = level[:id] @name = if @id.between?(31, 39) [nil, nil, :contributor, :former_staff, :janitor][@id - 30] else %i[unactivated blocked member privileged mod admin][@id / 10] end end |
Instance Attribute Details
#id ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns id of level.
28 29 30 |
# File 'lib/rubyhexagon/user/level.rb', line 28 def id @id end |
#name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns name of level.
31 32 33 |
# File 'lib/rubyhexagon/user/level.rb', line 31 def name @name end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Comparison method for Level objects
60 61 62 |
# File 'lib/rubyhexagon/user/level.rb', line 60 def ==(other) other.is_a?(Level) && @id == other.id && @name == other.name end |
#test ⇒ TrueClass|FalseClass Also known as: unactivated?, blocked?, member?, privileged?, contributor?, former_staff?, janitor?, mod?, admin?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test function for level names.
69 70 71 |
# File 'lib/rubyhexagon/user/level.rb', line 69 def test __callee__.to_s.sub(/\?/, '').to_sym == @name end |