Class: Synchronizer
- Inherits:
-
Object
- Object
- Synchronizer
- Defined in:
- lib/sync-strings.rb
Instance Method Summary collapse
-
#initialize(a_filename, b_filename) ⇒ Synchronizer
constructor
A new instance of Synchronizer.
- #key_differences ⇒ Object
- #key_differences? ⇒ Boolean
- #print_stats ⇒ Object
- #sync ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(a_filename, b_filename) ⇒ Synchronizer
Returns a new instance of Synchronizer.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sync-strings.rb', line 26 def initialize(a_filename, b_filename) @a_filename = a_filename @b_filename = b_filename @a_hash = Apfel.parse(@a_filename).to_hash(with_comments: false) @b_hash = Apfel.parse(@b_filename).to_hash(with_comments: false) @a_subtract_b = difference(@a_hash, @b_hash) @b_subtract_a = difference(@b_hash, @a_hash) end |
Instance Method Details
#key_differences ⇒ Object
44 45 46 |
# File 'lib/sync-strings.rb', line 44 def key_differences() @a_subtract_b + @b_subtract_a end |
#key_differences? ⇒ Boolean
48 49 50 |
# File 'lib/sync-strings.rb', line 48 def key_differences?() !@a_subtract_b.empty? || !@b_subtract_a.empty? end |
#print_stats ⇒ Object
37 38 39 40 41 42 |
# File 'lib/sync-strings.rb', line 37 def print_stats() puts "File A: #{@a_filename}" puts "File B: #{@b_filename}" puts "A - B = #{@a_subtract_b.length}" puts "B - A = #{@b_subtract_a.length}" end |
#sync ⇒ Object
52 53 54 55 |
# File 'lib/sync-strings.rb', line 52 def sync() add(@b_subtract_a, @a_hash) add(@a_subtract_b, @b_hash) end |
#write ⇒ Object
57 58 59 60 61 |
# File 'lib/sync-strings.rb', line 57 def write() writer = HashStringFileWriter.new writer.write(@a_hash, @a_filename) writer.write(@b_hash, @b_filename) end |