github_copier 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f65a16009f22048a6d1efb93d734bd5c936e99ec
4
- data.tar.gz: 2d6042100d7705c19166037abd9ada3eee891618
3
+ metadata.gz: b16b343dbdc33c67dfe9f484926b4d0d3bb38c5e
4
+ data.tar.gz: ecee64e8b27ffc211e19647028524dcbfaa85431
5
5
  SHA512:
6
- metadata.gz: b45a11433cf42353184a92da6af9edb0dd983fa8ab88c1f824ab576e3df42f979b2f0d59db98877bffb1db3d1a916fee73c3b7a6f14c28df8bfbe62f7aff034c
7
- data.tar.gz: 6c62d3a174b690fadd93d57f0c1928af00ed4031e63d9de9fe426ec6179567aa8bedb9dda55a38e9656276431eeb873d2dbea4eb812293a4c60dbdd1c700cf5d
6
+ metadata.gz: 3b33a8e35bae65110d8c50bcc9eeeea95a51e5424377a37b5a5800c0a08545d37e90d70d2e042312f9aa36ab71112ebf9d84492cd094fd0aaab2c21c9e842c6a
7
+ data.tar.gz: 5533a912dd20f3ad557bcc7654b91e5dc49f9919d086a0cdf71dffb021c13349630a455db5f66cf457af738da1bb3017537cec300581e885466911273e70e83b
@@ -5,7 +5,12 @@
5
5
  - Initial release
6
6
 
7
7
  #### 0.2.0
8
+
8
9
  - Add option to group output by language by default
9
10
  - Show list of repositories in the dry-run mode (--no-clone) option
10
11
  - Improve the gemspec to add more context for the user
11
12
  - Add some example to default option when the user type no argument
13
+
14
+ #### 0.2.1
15
+
16
+ - Remove the need from `filename_cleaner` and use it locally
data/README.md CHANGED
@@ -179,7 +179,6 @@ Process 1 of 1 : git clone git@github.com:littlebee/got.git /Users/bchoomnuan/De
179
179
 
180
180
  - Replace system call with the ruby library like [grit](https://github.com/mojombo/grit) or something similar
181
181
  - Allow the `https` when performing the clone
182
- - Implement the `FilenameCleaner.sanitize()` locally
183
182
 
184
183
  ### Related Projects
185
184
 
@@ -28,7 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_runtime_dependency 'github_api', '~> 0.13'
31
- spec.add_runtime_dependency 'filename_cleaner', '~> 0.4'
32
31
 
33
32
  spec.add_development_dependency 'awesome_print', '~> 1.6'
34
33
  spec.add_development_dependency 'bundler', '~> 1.10'
@@ -1,6 +1,6 @@
1
1
  require 'github_copier/version'
2
2
  require 'github_copier/opt_parser'
3
3
  require 'github_copier/github_copier'
4
+ require 'github_copier/filename_cleaner'
4
5
  require 'github_api'
5
- require 'filename_cleaner'
6
6
  include GithubCopier
@@ -0,0 +1,98 @@
1
+ module FilenameCleaner
2
+ DOT = "."
3
+ class << self
4
+ # Sanitize the any name with or without extension
5
+ #
6
+ # @param [String] name the input string
7
+ # @param [String] sep_char the separator char to be used
8
+ # @param [Boolean] have_extension indicate if the the input file should be
9
+ # treated as having extension or not having one
10
+ # @return [String] output string with special chars replaced withe specified string
11
+ def sanitize(name, sep_char = ".", have_extension = false)
12
+ if have_extension
13
+ sanitize_name_with_extension(name, sep_char)
14
+ else
15
+ sanitize_name_without_extension(name, sep_char)
16
+ end
17
+ end
18
+
19
+ # Get formatted name for existing file
20
+ #
21
+ # @param [String] filename the input filename
22
+ # @param [Hash<Symbol, Object>] opts the hash value for options to be applied
23
+ #
24
+ # @option opts [String] :sep_char The separator string
25
+ # @option opts [Boolean] :downcase Convert each word to lower case
26
+ # @option opts [Boolean] :capitalize: Capitalize each word in the name
27
+ def formatted_name(filename, opts = {})
28
+ sep_char = opts[:sep_char] || "."
29
+ sanitized_name = FilenameCleaner.sanitize(filename, sep_char, true)
30
+
31
+ # First split the two part so that only name is used!
32
+ basename = File.basename(sanitized_name, ".*")
33
+ extname = File.extname(sanitized_name)
34
+ if opts[:downcase]
35
+ basename = basename.split(sep_char).map(&:downcase).join(sep_char)
36
+ end
37
+ if opts[:capitalize]
38
+ basename = basename.split(sep_char).map(&:capitalize).join(sep_char)
39
+ end
40
+ "#{basename}#{extname}"
41
+ end
42
+
43
+ private
44
+
45
+ # Sanitize the any name with or without any extension
46
+ #
47
+ # @param [String] name the input string
48
+ # @param [String] sep_char the separator char to be used
49
+ # @return [String] output string with special chars replaced withe specified string
50
+ def sanitize_name_without_extension(name, sep_char = ".")
51
+ replace_dot(sanitize_with_dot(name), sep_char)
52
+ end
53
+
54
+ # Sanitize filename that works with file with extension
55
+ #
56
+ # @param [String] name the input filename with extension
57
+ # @return [String] the output file with special characters replaced
58
+ def sanitize_name_with_extension(name, sep_char = ".")
59
+ extension = File.extname(name)
60
+ name_only = File.basename(name, ".*")
61
+ name_only = replace_dot(sanitize_with_dot(name_only), sep_char)
62
+ "#{name_only}#{extension}"
63
+ end
64
+
65
+ # Replace the multiple special characters with a dot string
66
+ #
67
+ # @param [String] input_name input file
68
+ # @return [String] the new name with special characters replaced or removed.
69
+ def sanitize_with_dot(input_name)
70
+ # Don't mutate the input name
71
+ name = input_name.clone
72
+
73
+ # Replace any special characters with a dot
74
+ name.gsub!(/[^0-9A-Za-z\-_ ]/, DOT)
75
+
76
+ # Replace multiple occurrences of a given character with a dot
77
+ ["-", "_", " "].each do |c|
78
+ name.gsub!(/#{Regexp.quote(c)}+/, DOT)
79
+ end
80
+
81
+ # Replace multiple occurrence of dot with one dot
82
+ name.gsub!(/#{Regexp.quote(DOT)}+/, DOT)
83
+
84
+ # Remove the last char if it is a dot
85
+ name.gsub!(/\.$/, "") if name[-1] == DOT
86
+
87
+ # return the result
88
+ name
89
+ end
90
+
91
+ # Replace 'dot' string with a given string if specified
92
+ def replace_dot(string, replace = nil)
93
+ result = string.clone
94
+ result.gsub!(/#{Regexp.quote(DOT)}+/, replace) if replace
95
+ result
96
+ end
97
+ end
98
+ end
@@ -1,3 +1,3 @@
1
1
  module GithubCopier
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_copier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github_api
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.13'
27
- - !ruby/object:Gem::Dependency
28
- name: filename_cleaner
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.4'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: awesome_print
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -226,6 +212,7 @@ files:
226
212
  - bin/github_copier
227
213
  - github_copier.gemspec
228
214
  - lib/github_copier.rb
215
+ - lib/github_copier/filename_cleaner.rb
229
216
  - lib/github_copier/github_copier.rb
230
217
  - lib/github_copier/opt_parser.rb
231
218
  - lib/github_copier/version.rb