Sha256: 1d2138f60ed4c6ce1c09bdea1853ca0b35f02746bbce74b511a280afbd04e391
Contents?: true
Size: 1.67 KB
Versions: 10
Compression:
Stored size: 1.67 KB
Contents
#!/usr/bin/env ruby require 'utils' require 'tins/go' include Tins::GO require 'tins/xt/string' require 'term/ansicolor' def path_shifter(string, separator: ?/, n: nil) n or return string n, path = n.to_i, string.split(separator) if n < 0 path = path.slice(n..-1) else path.slice!(0...n) end path * separator end def underscore(string) string = path_shifter(string, n: $opts[?n], separator: '::') string = Tins::StringUnderscore.instance_method(:underscore).bind(string).() $opts[?s] and string << '.rb' string end def parameterize(string, separator) underscore(string).gsub(?/, separator) # quick and dirty end def camelize(string) string = path_shifter(string, n: $opts[?n]) string = string.gsub(/#{Regexp.quote(File.extname(string))}\Z/, '') string.camelize end def camelcase?(string) string[0, 1] =~ /[A-Z]/ end def compute_shift(config, string) string = underscore(string) result = config.classify.shift_path_by_default for prefix in config.classify.shift_path_for_prefix if string.start_with? prefix return prefix.count(?/) + 1 end end result end $opts = go 'bdtsp:n:' string = ARGV.shift or fail "need a class/filepath/filename" string = Term::ANSIColor.uncolor string config = Utils::ConfigFile.new config.configure_from_paths $opts[?n] ||= compute_shift(config, string) $opts[?b] and $opts[?n] = '-1' print case when $opts[?t] if camelcase?(string) if separator = $opts[?p] parameterize string, separator else underscore string end else camelize string end when $opts[?d] if separator = $opts[?p] parameterize string, separator else underscore string end else camelize string end
Version data entries
10 entries across 10 versions & 1 rubygems