Skip to content

Instantly share code, notes, and snippets.

@tfentonz
Last active August 29, 2015 14:03
Show Gist options
  • Save tfentonz/c0ed391e70c79beb422d to your computer and use it in GitHub Desktop.
Save tfentonz/c0ed391e70c79beb422d to your computer and use it in GitHub Desktop.
Append a fixed width format line to keywords file.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
def keywords_file
ENV['PJKKG'] + '01'
end
def keywords_line(project)
line = format('%-20s', project['project_id'])
line += ' ' + format('%-30s', project['name'])
line += ' ' + format('%-60s', project['description'])
line.strip
end
project = JSON.parse("{ \"project_id\": \"1234567\", \"name\": \"Project name\",
\"description\": \"Project description\" }")
open(keywords_file, 'a') { |f| f.puts keywords_line(project) } if File.exists?(keywords_file)
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment