fec 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2032e219e5071d35f5eae7eece797031994c814d
4
- data.tar.gz: 1ca6a9bd9b00455a7811e80d6fcd42c313242dbe
3
+ metadata.gz: 0202ab36bcf03852f076930b33f1adab85f10227
4
+ data.tar.gz: 2d2013c30e2b0f272b6a36ed62df1ed5e05889aa
5
5
  SHA512:
6
- metadata.gz: dbc8cedac359048814607e8c42910e5c32fe404d1cc086b2e4252bfc45f623f3be41df2b3b3c5ef626195f581d928560df2a1f065fcfc691fc8599ad2e3a9170
7
- data.tar.gz: 39be9f13523d1b095b93a66e37c0e71db98177114d8116272a0c3b6b31becff2c07c7cf8ebe0fc669f2a7b198bcb2beaa80256f7f9fc325c2171a24aabfd0b06
6
+ metadata.gz: fc9c1ea1067c7cb28e76a78e5074f9706298fc39f56cb1c26e1d1610a8259b693f4d38f0ab0c22b9e8e745b1c2bdf7116a471c9d2eb5320e2e4ae68a2c3b2a75
7
+ data.tar.gz: 60c0e879320a4d810b3dc047f12c182d364d0a353b7f15f3990deedffab77421ca62d0be1d44e9a1fc1a3d55796cd7ffadc806cee4b63902139a7e8236f79876
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.11.2'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'rspec'
28
29
  spec.add_development_dependency 'rubocop'
29
30
 
30
31
  # comment linter directly on pull request
@@ -3,6 +3,7 @@ require 'thor'
3
3
  require 'rainbow'
4
4
  require_relative 'file_helper'
5
5
  require_relative 'messenger'
6
+ require 'pry'
6
7
 
7
8
  module Fec
8
9
  class FileExtensionChanger < Thor
@@ -23,8 +24,8 @@ module Fec
23
24
  new_extension = options.fetch('new_extension')
24
25
 
25
26
  Dir.entries("#{folder_path}/").each do |name|
26
- if directory?(folder_path, name)
27
- path = "#{folder_path}/#{name}"
27
+ path = "#{folder_path}/#{name}"
28
+ if directory?(path)
28
29
  notice_message("Processing #{path}")
29
30
  rename(path)
30
31
  elsif name.downcase.include? old_extension
@@ -1,7 +1,10 @@
1
+ require 'pry'
1
2
  module Fec
2
3
  module FileHelper
3
- def directory?(parrent, path)
4
- File.directory?(File.join(parrent, path) && !(path == '.' || path == '..'))
4
+ def directory?(path)
5
+ parrent = File.expand_path('..', path)
6
+ path = File.basename(path)
7
+ File.directory?(File.join(parrent, path)) && !(path == '.' || path == '..')
5
8
  end
6
9
  end
7
10
  end
@@ -1,3 +1,3 @@
1
1
  module Fec
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -1,11 +1,28 @@
1
1
  require 'spec_helper'
2
+ require 'file_helper'
2
3
 
3
4
  describe Fec do
5
+ include FileHelper
6
+
7
+ let(:fec) { Fec::FileExtensionChanger.new }
8
+
4
9
  it 'has a version number' do
5
10
  expect(Fec::VERSION).not_to be nil
6
11
  end
7
12
 
8
- it 'does something useful' do
9
- expect(false).to eq(true)
13
+ it 'Rename success' do
14
+ old_file_extension = 'txt'
15
+ new_file_extension = 'new'
16
+ root = create_file(old_file_extension)
17
+ fec.options = {
18
+ 'old_extension' => old_file_extension,
19
+ 'new_extension' => new_file_extension
20
+ }
21
+ fec.rename root
22
+ files = files_in_folder(root)
23
+ true_expectation = all_files_contain_same_extension?(files, new_file_extension)
24
+ expect(true_expectation).to be true
25
+ false_expectation = all_files_contain_same_extension?(files, old_file_extension)
26
+ expect(false_expectation).to be false
10
27
  end
11
28
  end
@@ -0,0 +1,44 @@
1
+ require 'fec/file_helper'
2
+
3
+ module FileHelper
4
+ include Fec::FileHelper
5
+ def all_files_contain_same_extension?(files, extension)
6
+ files.each do |item|
7
+ return false unless File.extname(item).include? extension
8
+ end
9
+ true
10
+ end
11
+
12
+ def create_file(file_extension)
13
+ root = "#{Dir.tmpdir}/foo"
14
+ bar_path = "#{root}/bar"
15
+ lorem_path = "#{root}/lorem"
16
+ mkdir_and_create_file(root, file_extension)
17
+ mkdir_and_create_file(bar_path, file_extension)
18
+ mkdir_and_create_file(lorem_path, file_extension)
19
+ root
20
+ end
21
+
22
+ def files_in_folder(path)
23
+ files = []
24
+ Dir.entries(path).each do |name|
25
+ current_path = "#{path}/#{name}"
26
+ if directory?(current_path)
27
+ files_in_folder(current_path).each do |item|
28
+ files.push(item)
29
+ end
30
+ elsif name.length > 2
31
+ files.push(name)
32
+ end
33
+ end
34
+ files
35
+ end
36
+
37
+ private
38
+
39
+ def mkdir_and_create_file(folder_path, file_extension)
40
+ FileUtils.mkdir_p folder_path
41
+ file_name = "#{Time.now.to_f}.#{file_extension}"
42
+ File.open("#{folder_path}/#{file_name}", 'w') { |f| f.write('') }
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - CAO Quang Binh
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +162,7 @@ extensions: []
148
162
  extra_rdoc_files: []
149
163
  files:
150
164
  - ".gitignore"
165
+ - ".rspec"
151
166
  - ".rubocop.yml"
152
167
  - Gemfile
153
168
  - LICENSE.txt
@@ -165,6 +180,7 @@ files:
165
180
  - lib/fec/messenger.rb
166
181
  - lib/fec/version.rb
167
182
  - spec/fec_spec.rb
183
+ - spec/file_helper.rb
168
184
  - spec/spec_helper.rb
169
185
  homepage: https://github.com/CQBinh/fec
170
186
  licenses:
@@ -192,4 +208,5 @@ specification_version: 4
192
208
  summary: File Extension Changer.
193
209
  test_files:
194
210
  - spec/fec_spec.rb
211
+ - spec/file_helper.rb
195
212
  - spec/spec_helper.rb