Class: RosettAi::Licensing::Tier

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rosett_ai/licensing/tier.rb

Overview

Represents a license tier with comparable ordering.

Tiers control access to premium content pack downloads — they NEVER restrict software functionality (GPL-3.0 compliance).

Constant Summary collapse

HIERARCHY =
{ community: 0, supporter: 1, subscriber: 2, enterprise: 3 }.freeze
NAMES =
HIERARCHY.keys.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tier

Returns a new instance of Tier.



20
21
22
23
24
25
26
# File 'lib/rosett_ai/licensing/tier.rb', line 20

def initialize(name)
  sym = name.to_s.downcase.to_sym
  raise RosettAi::LicenseError, "unknown tier: #{name}" unless HIERARCHY.key?(sym)

  @name = sym
  @level = HIERARCHY[sym]
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



18
19
20
# File 'lib/rosett_ai/licensing/tier.rb', line 18

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/rosett_ai/licensing/tier.rb', line 18

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/rosett_ai/licensing/tier.rb', line 28

def <=>(other)
  level <=> other.level
end

#entitled_to?(required) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/rosett_ai/licensing/tier.rb', line 32

def entitled_to?(required)
  other = required.is_a?(Tier) ? required : Tier.new(required)
  self >= other
end

#to_sObject



37
38
39
# File 'lib/rosett_ai/licensing/tier.rb', line 37

def to_s
  name.to_s.capitalize
end