Class: FileNameHistory
- Inherits:
-
Object
- Object
- FileNameHistory
- Defined in:
- lib/filename_history.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(name, history = []) ⇒ FileNameHistory
constructor
A new instance of FileNameHistory.
- #last_name ⇒ Object
- #log(where = $stdout) ⇒ Object
- #original ⇒ Object
- #plan_reapplication(name) ⇒ Object
- #plan_rename(regexp, replacement) ⇒ Object
- #plan_rollback ⇒ Object
- #present? ⇒ Boolean
- #print_history(where = $stdout) ⇒ Object
- #rename ⇒ Object
- #to_hash ⇒ Object
- #was_named?(name) ⇒ Boolean
Constructor Details
#initialize(name, history = []) ⇒ FileNameHistory
Returns a new instance of FileNameHistory.
4 5 6 7 |
# File 'lib/filename_history.rb', line 4 def initialize(name, history = []) @history = history.empty? ? [name] : history @current = name end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
2 3 4 |
# File 'lib/filename_history.rb', line 2 def current @current end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
2 3 4 |
# File 'lib/filename_history.rb', line 2 def history @history end |
Class Method Details
.new_from_history(history) ⇒ Object
15 16 17 18 |
# File 'lib/filename_history.rb', line 15 def self.new_from_history(history) FileNameHistory.new(history.last, history) end |
Instance Method Details
#changed? ⇒ Boolean
49 50 51 |
# File 'lib/filename_history.rb', line 49 def changed? @history.last != @current end |
#last_name ⇒ Object
28 29 30 |
# File 'lib/filename_history.rb', line 28 def last_name @history.last end |
#log(where = $stdout) ⇒ Object
63 64 65 66 67 |
# File 'lib/filename_history.rb', line 63 def log(where = $stdout) return unless changed? where.puts(@current) where.puts("-> #{@history.last}") end |
#original ⇒ Object
24 25 26 |
# File 'lib/filename_history.rb', line 24 def original @history.first end |
#plan_reapplication(name) ⇒ Object
45 46 47 |
# File 'lib/filename_history.rb', line 45 def plan_reapplication(name) @current = name end |
#plan_rename(regexp, replacement) ⇒ Object
32 33 34 35 |
# File 'lib/filename_history.rb', line 32 def plan_rename(regexp, replacement) new_name = @current.gsub(regexp, replacement) @history << new_name if new_name != current end |
#plan_rollback ⇒ Object
37 38 39 |
# File 'lib/filename_history.rb', line 37 def plan_rollback @history << original end |
#present? ⇒ Boolean
20 21 22 |
# File 'lib/filename_history.rb', line 20 def present? File.exist?(@current) end |
#print_history(where = $stdout) ⇒ Object
58 59 60 61 |
# File 'lib/filename_history.rb', line 58 def print_history(where = $stdout) where.puts(@current) where.print "-> #{@history.join("\n-> ")}\n\n" end |
#rename ⇒ Object
53 54 55 56 |
# File 'lib/filename_history.rb', line 53 def rename File.rename("#{@current}", "#{@history.last}") @current = @history.last end |
#to_hash ⇒ Object
9 10 11 12 13 |
# File 'lib/filename_history.rb', line 9 def to_hash { @history.last => @history } end |
#was_named?(name) ⇒ Boolean
41 42 43 |
# File 'lib/filename_history.rb', line 41 def was_named?(name) @history.include? name end |