Class: SafeDiff
- Inherits:
-
Object
- Object
- SafeDiff
- Defined in:
- lib/safediff.rb
Overview
SafeDiff Contains a difference between two safe entries
Constant Summary collapse
- MASTER =
"m"
- OTHER =
"o"
- CHANGE =
"c"
Instance Attribute Summary collapse
-
#master ⇒ Object
Returns the value of attribute master.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#other ⇒ Object
Returns the value of attribute other.
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(master, other) ⇒ SafeDiff
constructor
A new instance of SafeDiff.
- #to_s ⇒ Object
Constructor Details
#initialize(master, other) ⇒ SafeDiff
Returns a new instance of SafeDiff.
46 47 48 49 50 |
# File 'lib/safediff.rb', line 46 def initialize(master, other) self.master = master self.other = other compare end |
Instance Attribute Details
#master ⇒ Object
Returns the value of attribute master.
40 41 42 |
# File 'lib/safediff.rb', line 40 def master @master end |
#operation ⇒ Object
Returns the value of attribute operation.
40 41 42 |
# File 'lib/safediff.rb', line 40 def operation @operation end |
#other ⇒ Object
Returns the value of attribute other.
40 41 42 |
# File 'lib/safediff.rb', line 40 def other @other end |
Instance Method Details
#compare ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/safediff.rb', line 52 def compare if self.master != nil && self.master.equals?(self.other) raise "Entries are not different:\n#{self.master.to_s}\n#{self.other.to_s}" elsif self.master != nil && self.other == nil self.operation = MASTER elsif self.master == nil && self.other != nil self.operation = OTHER else self.operation = CHANGE end end |
#to_s ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/safediff.rb', line 64 def to_s s = "" s << self.operation s << "\n" if self.operation == MASTER || self.operation == CHANGE s << "< " s << self.master.to_s s << "\n" end if self.operation == CHANGE s << "---\n" end if self.operation == OTHER || self.operation == CHANGE s << "> " s << self.other.to_s s << "\n" end s end |