Skip to content

Instantly share code, notes, and snippets.

@tansengming
Last active December 18, 2015 22:29
Show Gist options
  • Save tansengming/5855268 to your computer and use it in GitHub Desktop.
Save tansengming/5855268 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_support'
require 'pathname'
# require 'tapp'
class ToParams
attr_reader :pathname
def initialize(path)
@pathname = Pathname.new path
raise ArgumentError, "#{pathname} not found!" unless pathname.exist?
end
def process
pathname.rename params_full_path
end
private
def params_full_path
File.join(dir, "#{params_name}#{extension}")
end
def params_name
ActiveSupport::Inflector::underscore basename
end
def basename
pathname.sub_ext('').basename
end
def dir
pathname.dirname
end
def extension
pathname.extname
end
end
HELP_TEXT=<<EOF
To use:
ruby cc-to-params.rb FILE1 FILE2 FILE3 ...
(will rename CamelCaseFiles to camel_case_files)
EOF
if $0 == __FILE__
abort(HELP_TEXT) if (ARGV[0] && ARGV[0] == '-h')
ARGV.each do |path|
ToParams.new(path).process
end
end
@tansengming
Copy link
Author

-1 for not embedding a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment