rbname 0.0.1 → 0.0.2

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGY3MWE4ZTMxYWE2ZmE0OTVhMWMyOTFlOTI1OTMzNzQ0ZWFmNGM2MQ==
5
+ data.tar.gz: !binary |-
6
+ NDg5MDE3YzllNWJlNDY1MTk4YjkxYzU2ZjJkZDhlMTRmY2YyM2VkMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODFiYzZjNGRjNWEyZWYxNDdiZWI3OWJjYmQ5MzRmY2I0MGE0ODdhYTRlYmEw
10
+ NjExOGJlYWZmMjNjN2E2NDI3NTYwZTM3YmQ2MjQ3ZTAyZTAyZDMyZGU1MDkw
11
+ MjM3MjJmNzE4NzdiNmQxNTAzNzYwOTk5ZTU3NzVmMzU3MzJlOTE=
12
+ data.tar.gz: !binary |-
13
+ NjlkNzEyYWJjNzg5MWRmMWVkYWM4MjlhNGRmOWM5ODM4M2FmMDJkOGExOTkw
14
+ M2Q0NTFjZjk1MjM1NTg3N2VmMjdiMmMzNzA1MDAzMTgxY2Q4ZmJmMzdjMjc5
15
+ M2M3M2UwMzY3MWRiYTdmMDIxZWU2NGY4NTgxZTMyMDNhODVmZmQ=
@@ -4,18 +4,19 @@ require 'file_line_presenter'
4
4
  class ChangePrompt
5
5
  LINES_OF_CONTEXT = 2
6
6
  USE_EDITOR = "E"
7
+ HORIZONTAL_LINE = "-" * 100
7
8
 
8
9
  attr_reader :user_input
9
10
 
10
11
  def self.prompt(pattern, file_line, replacements)
11
12
  present_line(file_line, pattern)
12
13
  puts("How would you like to update the above line? Options below. Hit return to do nothing\n\n")
13
- puts "------------------------------"
14
+ puts HORIZONTAL_LINE
14
15
  puts("#{USE_EDITOR}: Edit in Vi")
15
16
  replacements.each_with_index do |replacement, index|
16
17
  puts "#{index}: #{replacement.suggest(file_line.raw_contents)}"
17
18
  end
18
- puts "------------------------------"
19
+ puts HORIZONTAL_LINE
19
20
  user_input = gets
20
21
  puts("")
21
22
  ChangePrompt.new(user_input)
@@ -39,11 +40,11 @@ class ChangePrompt
39
40
  private
40
41
 
41
42
  def self.present_line(file_line, pattern)
42
- puts "-----------------------------------"
43
+ puts HORIZONTAL_LINE
43
44
  puts("FILENAME: #{file_line.path}")
44
- puts "-----------------------------------"
45
+ puts HORIZONTAL_LINE
45
46
  puts(FileLinePresenter.present_contents(file_line, pattern, LINES_OF_CONTEXT))
46
- puts "-----------------------------------"
47
+ puts HORIZONTAL_LINE
47
48
  puts "\n"
48
49
  end
49
50
  end
@@ -4,13 +4,8 @@ require 'replacement_collection'
4
4
 
5
5
  class Main
6
6
  def self.replace_all
7
- puts "We will be replacing some text today."
8
- puts "What is a pattern describing the text you want to replace?"
9
- pattern = gets.chomp
10
- puts ""
11
- puts "What is root of your search? ('.' would probably work fine)"
12
- root_path = gets.chomp
13
- puts ""
7
+
8
+ pattern, root_path = prompt_search_details
14
9
 
15
10
  file_lines = FileLine.find_all(pattern, root_path)
16
11
  replacement_collection = ReplacementCollection.new
@@ -22,9 +17,9 @@ class Main
22
17
  user_input = ChangePrompt.prompt(pattern, file_line, applicable_replacements)
23
18
  if user_input.chose_editor?
24
19
  edit_with_vim!(file_line, pattern)
25
- update_replacement_collection!(replacement_collection, old_contents, file_line)
20
+ record_manual_replacement!(replacement_collection, old_contents, file_line)
26
21
  elsif user_input.integer_input
27
- update_according_to_sugestion(user_input.integer_input, applicable_replacements, file_line)
22
+ take_user_suggestion!(user_input.integer_input, applicable_replacements, file_line)
28
23
  end
29
24
  end
30
25
  end
@@ -32,12 +27,23 @@ class Main
32
27
 
33
28
  private
34
29
 
35
- def self.update_replacement_collection!(replacement_collection, old_contents, file_line)
36
- new_contents = file_line.raw_contents
37
- replacement_collection << Replacement.generate(old_contents, new_contents) unless old_contents == new_contents
30
+ def self.prompt_search_details
31
+ puts "We will be replacing some text today."
32
+ puts "What is a pattern describing the text you want to replace?"
33
+ pattern = gets.chomp
34
+ puts ""
35
+ puts "What is root of your search? ('.' would probably work fine)"
36
+ root_path = gets.chomp
37
+ puts ""
38
+ [pattern, root_path]
39
+ end
40
+
41
+ def self.record_manual_replacement!(replacement_collection, old_contents, file_line)
42
+ new_contents = file_line.raw_contents
43
+ replacement_collection << Replacement.generate(old_contents, new_contents) unless old_contents == new_contents
38
44
  end
39
45
 
40
- def self.update_according_to_sugestion(integer_input, applicable_replacements, file_line)
46
+ def self.take_user_suggestion!(integer_input, applicable_replacements, file_line)
41
47
  replacement = applicable_replacements[integer_input]
42
48
  new_contents = replacement.suggest(file_line.raw_contents)
43
49
  file_line.update_filesystem!(new_contents)
@@ -27,7 +27,7 @@ class Replacement
27
27
 
28
28
  def suggest(to_change)
29
29
  if to_change.match(to_replace)
30
- to_change.gsub(to_replace, new_text)
30
+ to_change.sub(to_replace, new_text)
31
31
  end
32
32
  end
33
33
 
@@ -1,7 +1,7 @@
1
1
  class ReplacementCollection < Array
2
2
  def applicable_replacements(line_contents)
3
3
  select do |replacement|
4
- line_contents.match(replacement.to_replace)
4
+ line_contents.match(Regexp.escape(replacement.to_replace))
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbname
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Wai Lee Chin Feman
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: colorize
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -60,26 +55,25 @@ files:
60
55
  homepage: http://github.com/skatenerd
61
56
  licenses:
62
57
  - MIT
58
+ metadata: {}
63
59
  post_install_message:
64
60
  rdoc_options: []
65
61
  require_paths:
66
62
  - lib
67
63
  required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
64
  requirements:
70
65
  - - ! '>='
71
66
  - !ruby/object:Gem::Version
72
67
  version: '0'
73
68
  required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
69
  requirements:
76
70
  - - ! '>='
77
71
  - !ruby/object:Gem::Version
78
72
  version: '0'
79
73
  requirements: []
80
74
  rubyforge_project:
81
- rubygems_version: 1.8.25
75
+ rubygems_version: 2.1.2
82
76
  signing_key:
83
- specification_version: 3
77
+ specification_version: 4
84
78
  summary: CLI Find/Replace
85
79
  test_files: []