Class: ESA::Flag

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Includes:
Traits::Extendable
Defined in:
app/models/esa/flag.rb

Overview

The Flag class represents a change of known state of an Accountable and it is used record differences of state caused by Events.

A Flag with an UP transition creates normal Transactions according to the rules specified in a Ruleset. Flags with a DOWN transition revert Transactions created earlier by the corresponding UP transition.

Author:

  • Lenno Nagel

Instance Method Summary collapse

Instance Method Details

#became_set?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/esa/flag.rb', line 45

def became_set?
  self.transition == 1
end

#became_unset?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/esa/flag.rb', line 49

def became_unset?
  self.transition == -1
end

#is_set?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/esa/flag.rb', line 37

def is_set?
  self.state == true
end

#is_unset?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/esa/flag.rb', line 41

def is_unset?
  self.state == false
end

#matches_spec?(spec) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'app/models/esa/flag.rb', line 53

def matches_spec?(spec)
  self.nature == spec[:nature].to_s and
  self.state == spec[:state]
end

#transactions_match_specs?(specs) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'app/models/esa/flag.rb', line 58

def transactions_match_specs?(specs)
  if self.transactions.count == specs.count
    self.transactions.map do |tx|
      tx_spec = specs.find{|a| a[:description] == tx.description} || {}
      tx.matches_spec?(tx_spec)
    end.all?
  else
    false
  end
end