compare_files 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efbbf413c5eab3072e4a4fe3f1ab039e48ae03ec
4
+ data.tar.gz: 5e0fe86a88998cff1cb1612c7eec544dd28fcd4c
5
+ SHA512:
6
+ metadata.gz: cf5f18999caeb9e98b7f46e2569822575579b0c186fe931e1410687c4742ed8413f5a3add79a2199c1a72e208e7f148b1fc5e9093fb1aaecb45105a6524adbb5
7
+ data.tar.gz: 2a62d72fbe65c8555fceb4b17d99fcc8a284c1c058b0e2b500e7100c2364052c9e5378f19f0653ec578007af7d2c1191560f0c0a9cfb41253454f432fdcd80c7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ compare_files
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in compare_files.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick Zubariev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ The program for comparing of two files per each line.
2
+
3
+ #### Setting up project
4
+ ##### Preferable to use ruby -v 2.3.0.
5
+
6
+ * Add to your project Gemfile following line
7
+
8
+ gem 'compare_files', '~> 0.1.0'
9
+
10
+ * Run from terminal
11
+
12
+ bundle install
13
+
14
+ * Add to your project Rakefile
15
+
16
+ spec = Gem::Specification.find_by_name 'compare_files'
17
+
18
+ load "#{spec.gem_dir}/lib/tasks/compare_files.rake"
19
+
20
+ * Run from terminal rake task (use two parameters: 2 files with absolute paths)
21
+
22
+ Example:
23
+ rake compare FILE1=/home/nz/projects/ruby/agile_engine/1.txt FILE2=/home/nz/projects/ruby/agile_engine/2.txt
24
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ # Importing the tasks files to rake
4
+ Dir.glob('lib/tasks/*.rake').each { |r| import r }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "compare_files"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'compare_files/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "compare_files"
8
+ spec.version = CompareFiles::VERSION
9
+ spec.authors = ["Nick Zubariev"]
10
+ spec.email = ["nick.zubariev@gmail.com"]
11
+
12
+ spec.summary = "The gem for comparing content of two files."
13
+ spec.description = "Compares content of two files."
14
+ spec.homepage = "https://github.com/nzubariev/files_comparing"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = "~> 2.3.0"
23
+
24
+ spec.add_runtime_dependency "bundler", "~> 1.11"
25
+ spec.add_runtime_dependency "rake", "~> 10.0"
26
+ spec.add_runtime_dependency "activesupport", "~> 5.0"
27
+ end
@@ -0,0 +1,53 @@
1
+ require "compare_files/version"
2
+ require "active_support/core_ext/string"
3
+
4
+ module CompareFiles
5
+ class Base
6
+
7
+ def initialize(file1, file2)
8
+ @file1array = array_from_file_lines(file1)
9
+ @file2array = array_from_file_lines(file2)
10
+ end
11
+
12
+ def compare
13
+ @result_array = []
14
+
15
+ (0...max_arrays_length).each do |i|
16
+ make_result_array(@file1array[i], @file2array[i])
17
+ end
18
+
19
+ print_result
20
+ end
21
+
22
+ private
23
+
24
+ def array_from_file_lines(file_path)
25
+ IO.readlines(file_path).map(&:chomp)
26
+ end
27
+
28
+ def max_arrays_length
29
+ instance_arrays = []
30
+
31
+ self.instance_variables.each do |inst_var|
32
+ instance_arrays << self.instance_variable_get(inst_var)
33
+ end
34
+
35
+ instance_arrays.map(&:length).max
36
+ end
37
+
38
+ def make_result_array(arr1value, arr2value)
39
+ case
40
+ when arr1value.blank? && arr2value.blank? then return
41
+ when arr1value.present? && arr2value.blank? then @result_array << "- #{arr1value}"
42
+ when arr1value.blank? && arr2value.present? then @result_array << "+ #{arr2value}"
43
+ when arr1value == arr2value then @result_array << " #{arr1value}"
44
+ when arr1value != arr2value then @result_array << "* #{arr1value} | #{arr2value}"
45
+ end
46
+ end
47
+
48
+ def print_result
49
+ @result_array.each_with_index { |arr, index| puts "#{index+1} #{arr}" }
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module CompareFiles
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../compare_files'
2
+
3
+ desc 'Comparing files content per each line.'
4
+ task :compare do
5
+ file1_path = ENV['FILE1']
6
+ file2_path = ENV['FILE2']
7
+
8
+ files = CompareFiles::Base.new(file1_path, file2_path)
9
+ files.compare
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compare_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Zubariev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Compares content of two files.
56
+ email:
57
+ - nick.zubariev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - compare_files.gemspec
73
+ - lib/compare_files.rb
74
+ - lib/compare_files/version.rb
75
+ - lib/tasks/compare_files.rake
76
+ homepage: https://github.com/nzubariev/files_comparing
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 2.3.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: The gem for comparing content of two files.
100
+ test_files: []