From 3af6827875f4e02b47fe2293280ff9afe811485f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 12 Feb 2008 16:35:31 -0600 Subject: Adding an inflection util class. --- lib/puppet/util/constant_inflector.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/puppet/util/constant_inflector.rb (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/constant_inflector.rb b/lib/puppet/util/constant_inflector.rb new file mode 100644 index 000000000..8b083951f --- /dev/null +++ b/lib/puppet/util/constant_inflector.rb @@ -0,0 +1,14 @@ +# Created on 2008-02-12 +# Copyright Luke Kanies + +# A common module for converting between constants and +# file names. +module Puppet::Util::ConstantInflector + def file2constant(file) + file.split("/").collect { |name| name.capitalize }.join("::").gsub(/_+(.)/) { |term| $1.capitalize } + end + + def constant2file(constant) + constant.to_s.gsub(/([a-z])([A-Z])/) { |term| $1 + "_" + $2 }.gsub("::", "/").downcase + end +end -- cgit