Class: Expire::RuleBase

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/expire/rule_base.rb

Overview

Base class of all rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:) ⇒ RuleBase



26
27
28
# File 'lib/expire/rule_base.rb', line 26

def initialize(amount:)
  @amount = amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



30
31
32
# File 'lib/expire/rule_base.rb', line 30

def amount
  @amount
end

Class Method Details

.<=>(other) ⇒ Object



8
9
10
# File 'lib/expire/rule_base.rb', line 8

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

.camelized_nameObject



12
13
14
15
# File 'lib/expire/rule_base.rb', line 12

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

.nameObject



17
18
19
# File 'lib/expire/rule_base.rb', line 17

def self.name
  camelized_name&.underscore
end

.option_nameObject



21
22
23
24
# File 'lib/expire/rule_base.rb', line 21

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

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
# File 'lib/expire/rule_base.rb', line 45

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

#nameObject



32
33
34
# File 'lib/expire/rule_base.rb', line 32

def name
  camelized_name&.underscore
end

#numerus_backupObject



36
37
38
# File 'lib/expire/rule_base.rb', line 36

def numerus_backup
  "backup".pluralize(amount)
end

#option_nameObject



40
41
42
43
# File 'lib/expire/rule_base.rb', line 40

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