Class: ActiveReport::SignedEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/active_report/base.rb

Overview

An Entry class designed to store the sign on the entry for easier manipulation of the stored object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object = nil, sign = :positive) ⇒ SignedEntry

Creates a new SignedEntry. The sign parameter defaults to :positive but accepts any object. If one of the following values are entered for the sign, the sign is automatically converted to a 1 or -1 depending upon the value entered.

  • true

  • false

  • :true, :positive

  • :false, :negative

  • "true", "positive"

  • "false", "negative"



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_report/base.rb', line 51

def initialize(object = nil, sign = :positive)
  @object = object
  
  @sign = case
    when sign.to_s.eql?("true") then 1
    when sign.to_s.eql?("false") then -1
    when sign.to_s.eql?("positive") then 1
    when sign.to_s.eql?("negative") then -1
    else sign
  end
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



37
38
39
# File 'lib/active_report/base.rb', line 37

def object
  @object
end

#signObject

Returns the value of attribute sign.



37
38
39
# File 'lib/active_report/base.rb', line 37

def sign
  @sign
end

Instance Method Details

#negative?Boolean Also known as: debit?

Returns true if the sign is less than 0.

This method is aliased as debit?.

Returns:

  • (Boolean)


75
76
77
# File 'lib/active_report/base.rb', line 75

def negative?
  @sign < 0
end

#positive?Boolean Also known as: credit?

Returns true if the sign is greater than or equal to 0.

This method is aliased as credit?.

Returns:

  • (Boolean)


66
67
68
# File 'lib/active_report/base.rb', line 66

def positive?
  @sign >= 0
end