summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/constant_inflector.rb
blob: eeeaa06321f3833af5637772c3730f5e2f2ad9fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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)
        # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com] 
        x = 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