Class: Itinerary::EditTool
- Inherits:
-
Tool
- Object
- Tool
- Itinerary::EditTool
show all
- Defined in:
- lib/itinerary/tools/edit.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tool
find_tool, inherited, #initialize, tools
Class Method Details
.name ⇒ Object
4
5
6
|
# File 'lib/itinerary/tools/edit.rb', line 4
def self.name
'edit'
end
|
Instance Method Details
#parse(args) ⇒ Object
8
9
10
|
# File 'lib/itinerary/tools/edit.rb', line 8
def parse(args)
@recs = args.map { |id| @itinerary[id] or raise "No record with id #{id.inspect}" }
end
|
#run ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/itinerary/tools/edit.rb', line 12
def run
@recs.each do |rec|
old_rec = rec.dup
rec.edit(:wait => true)
rec = Record.load(rec.path)
if rec == old_rec
warn "Unchanged"
next
end
unless rec.geocoded?
rec.geocode or raise "Failed to geocode #{rec.address.inspect} (entry left in #{rec.path})"
rec.save!
end
old_rec.print_diff(rec)
new_path = rec.make_path(@itinerary.entries_path)
if new_path != rec.path
old_path = rec.path
rec.path.rename(new_path)
rec.path = new_path
warn "Renamed #{old_path} to #{new_path}"
end
end
end
|