rickumali (130) [Avatar] Offline
#1
I've decided to write a short blog-type post every week here on this forum. These posts are exclusive to this forum, and they will primarily be about the writing of the book.

Earlier in the year, I wrote about a simple script to rename the raw picture files into the correctly named files expected by the publisher. That script is now much more complex. Instead of a single BASH script single-handedly renaming files, it is now a Ruby script that reads a master list of figures.

The program evolved because as the book progressed, I began moving pictures into different places. This required manually renumbering the figures in the script itself. I realized that the script could handle the numbering of the pictures. The Ruby program that I wrote reads a master list of figures. Whenever there is a new chapter, I insert a line with a two-digit number signifying this.

The master file looks like this:
# This is used by work_figures.rb
# This is the master list of figures in the gitbook
# Use work_figures to get the figure_map.csv file
01
single_point_of_contention
distributed
02
vc-personal
vc-personal-with-saves
vc-org

In the example, 01 and 02 represent the start of chapters 1 and 2. Whenever I move the figures around, I don't have to calculate the number. I just move the picture to the right spot, and ask the program to renumber the list. In the above listing, single_point_of_contention is renamed to 01_01.png. The program not only renumbers the files, it generates a CSV file that maps the figure to the correct figure number, and it copies the correctly named figures into a directory that I can compress and send to the publisher.

For people who want to try this out, the program is on a GitHub gist:

https://gist.github.com/rickumali/bad0be8fad81e03ae207

Check it out! Thank You for reading!