Class: Expire::FromNowKeepAdjectiveForRuleBase

Inherits:
KeepAdjectiveRuleBase show all
Extended by:
FromRangeValue
Includes:
NumerusUnit
Defined in:
lib/expire/from_now_keep_adjective_for_rule_base.rb

Overview

Base class for from-now rules

Constant Summary collapse

PRIMARY_RANK =
40

Constants included from FromRangeValue

Expire::FromRangeValue::FROM_VALUE_REGEX

Constants inherited from KeepAdjectiveRuleBase

KeepAdjectiveRuleBase::NOUN_FOR, KeepAdjectiveRuleBase::SECONDARY_RANK_FOR

Instance Attribute Summary collapse

Attributes inherited from RuleBase

#amount

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FromRangeValue

from_value

Methods included from NumerusUnit

#numerus_unit

Methods inherited from KeepAdjectiveRuleBase

#adjective, from_value, rank, #rank, secondary_rank, #secondary_rank, #spacing

Methods inherited from RuleBase

<=>, #<=>, camelized_name, #name, name, #numerus_backup, option_name, #option_name

Constructor Details

#initialize(unit:, **args) ⇒ FromNowKeepAdjectiveForRuleBase

Returns a new instance of FromNowKeepAdjectiveForRuleBase.



15
16
17
18
19
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 15

def initialize(unit:, **args)
  super(**args)

  @unit = unit
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



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

def unit
  @unit
end

Class Method Details

.primary_rankObject



11
12
13
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 11

def self.primary_rank
  PRIMARY_RANK
end

Instance Method Details

#apply(backups, reference_time) ⇒ Object



23
24
25
26
27
28
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 23

def apply(backups, reference_time)
  minimal_time = reference_time - amount.send(unit)
  kept = backups.one_per(spacing).not_older_than(minimal_time)

  kept.each { |backup| backup.add_reason_to_keep(reason_to_keep) }
end

#primary_rankObject



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

def primary_rank
  self.class.primary_rank
end

#reason_to_keepObject



34
35
36
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 34

def reason_to_keep
  "from now keep all backups for #{amount} #{numerus_unit}"
end