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 =

Returns Ordered tier hierarchy from lowest to highest.

Returns:

  • (Hash)

    Ordered tier hierarchy from lowest to highest.

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

Returns Human-readable names for each tier.

Returns:

  • (Object)

    Human-readable names for each tier.

HIERARCHY.keys.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tier

Returns a new instance of Tier.



23
24
25
26
27
28
29
# File 'lib/rosett_ai/licensing/tier.rb', line 23

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.



21
22
23
# File 'lib/rosett_ai/licensing/tier.rb', line 21

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/rosett_ai/licensing/tier.rb', line 21

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare tier levels for sorting.

Parameters:

  • other (Tier)

    the other tier to compare

Returns:

  • (Integer)

    -1, 0, or 1



35
36
37
# File 'lib/rosett_ai/licensing/tier.rb', line 35

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

#entitled_to?(required) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/rosett_ai/licensing/tier.rb', line 39

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

#to_sString

Return the human-readable tier name.

Returns:

  • (String)


46
47
48
# File 'lib/rosett_ai/licensing/tier.rb', line 46

def to_s
  name.to_s.capitalize
end