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.
43 44 45 46 47 |
# File 'lib/safediff.rb', line 43 def initialize(master, other) self.master = master self.other = other compare end |
Instance Attribute Details
#master ⇒ Object
Returns the value of attribute master.
37 38 39 |
# File 'lib/safediff.rb', line 37 def master @master end |
#operation ⇒ Object
Returns the value of attribute operation.
37 38 39 |
# File 'lib/safediff.rb', line 37 def operation @operation end |
#other ⇒ Object
Returns the value of attribute other.
37 38 39 |
# File 'lib/safediff.rb', line 37 def other @other end |
Instance Method Details
#compare ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/safediff.rb', line 49 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/safediff.rb', line 61 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 |