Sha256: 7a9e77ee41de997ac2a61ec16641e9292b4324bb3d8a529cb076dfc587a04be4

Contents?: true

Size: 929 Bytes

Versions: 3

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

module Expire
  # Base class of all rules
  class RuleBase
    include Comparable

    def self.<=>(other)
      rank <=> other.rank
    end

    def self.camelized_name
      match = to_s.match(/\A.*::(.+)Rule\z/) || return
      match[1]
    end

    def self.name
      camelized_name&.underscore
    end

    def self.option_name
      rule_name = name || return
      "--#{rule_name.dasherize}"
    end

    def initialize(amount:)
      @amount = amount
    end

    attr_reader :amount

    def name
      camelized_name&.underscore
    end

    def numerus_backup
      'backup'.pluralize(amount)
    end

    def option_name
      rule_name = name || return
      "--#{rule_name.dasherize}"
    end

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

    private

    def camelized_name
      match = self.class.to_s.match(/\A.*::(.+)Rule\z/) || return
      match[1]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
expire-0.2.2 lib/expire/rule_base.rb
expire-0.2.1 lib/expire/rule_base.rb
expire-0.2.0 lib/expire/rule_base.rb