module Genio::Util::NamespaceHelper
Public Instance Methods
Capitalizes parts of a package name eg: paypal.github.payments.sale is converted to Paypal.Github.Payments.Sale
# File lib/genio/util/namespace_helper.rb, line 58 def capitalize_package(packagename) packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase } end
Checks the format of the namespace as uri or urn, and converts the namespace to package name (‘.’ seperated) eg: github.paypal.com/payments/sale is changed to com.paypal.github.payments.sale eg: urn:ebay:apis:eBLBaseComponents is changed to urn.ebay.apis.eBLBaseComponents any numbers occuring as a part of path in the uri based namespaces is removed
# File lib/genio/util/namespace_helper.rb, line 29 def convert_ns_to_package(ns) if is_urn_ns(ns) packagename = ns.gsub(/:/, "\.") else hostname = URI.parse(ns) packagename = hostname.host.sub(/^www./, "").split(".").reverse.join(".") packagename << hostname.path.to_s.gsub(/[\d-]+/, "").sub(/\/+$/,'').gsub(/-/, '_').gsub(/\/+/, ".") end packagename end
Returns a folder path corresponding to the packagename; setting capitalize_folder true returns folder names that are captialized
# File lib/genio/util/namespace_helper.rb, line 65 def get_package_folder(packagename, capitalize_folder = false) if (capitalize_folder) capitalize_package(packagename).gsub(/\.|\\/, '/') else packagename.gsub(/\.|\\/, '/') end end
Returns a namespace path with ‘' corresponding to the packagename; setting capitalizefolder true returns
names that are captialized
# File lib/genio/util/namespace_helper.rb, line 76 def get_slashed_package_name(packagename, capitalizefolder = false) if (capitalizefolder) capitalize_package(packagename).gsub(/\./, '\\') else packagename.gsub(/\./, '\\') end end
Checks if the uri starts with protocol schemes and returns true, else treats the namespace as a Uniform Resource Name
# File lib/genio/util/namespace_helper.rb, line 87 def is_urn_ns(ns) !ns.start_with?('http:','https:') end
Lowercases parts of a package name eg: Paypal.Github.Payments.Sale is converted to paypal.github.payments.sale
# File lib/genio/util/namespace_helper.rb, line 51 def lowercase_package(packagename) packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase(:lower) } end
Strips a package name off any Top Level Domains (TLD)s; com, co, org, gov, de, us, in eg: com.paypal.github.payments.sale is converted to paypal.github.payments.sale
# File lib/genio/util/namespace_helper.rb, line 44 def remove_tld_in_package(packagename) packagename.sub(/^(com|co|org|gov|de|us|in)\./, "") end