Last active
December 18, 2015 22:29
-
-
Save tansengming/5855268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-1 for not embedding a test