Module: Genio::Util::NamespaceHelper
- Included in:
- Helper::Java, Tasks
- Defined in:
- lib/genio/util/namespace_helper.rb
Instance Method Summary collapse
-
#capitalize_package(packagename) ⇒ Object
Capitalizes parts of a package name eg: paypal.github.payments.sale is converted to Paypal.Github.Payments.Sale.
-
#convert_ns_to_package(ns) ⇒ Object
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.
-
#get_package_folder(packagename, capitalize_folder = false) ⇒ Object
Returns a folder path corresponding to the packagename; setting capitalize_folder true returns folder names that are captialized.
-
#get_slashed_package_name(packagename, capitalizefolder = false) ⇒ Object
Returns a namespace path with ‘' corresponding to the packagename; setting capitalizefolder true returns names that are captialized.
-
#is_urn_ns(ns) ⇒ Object
Checks if the uri starts with protocol schemes and returns true, else treats the namespace as a Uniform Resource Name.
-
#lowercase_package(packagename) ⇒ Object
Lowercases parts of a package name eg: Paypal.Github.Payments.Sale is converted to paypal.github.payments.sale.
-
#remove_tld_in_package(packagename) ⇒ Object
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.
Instance Method Details
#capitalize_package(packagename) ⇒ Object
Capitalizes parts of a package name eg: paypal.github.payments.sale is converted to Paypal.Github.Payments.Sale
58 59 60 |
# File 'lib/genio/util/namespace_helper.rb', line 58 def capitalize_package(packagename) packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase } end |
#convert_ns_to_package(ns) ⇒ Object
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
29 30 31 32 33 34 35 36 37 38 |
# 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 |
#get_package_folder(packagename, capitalize_folder = false) ⇒ Object
Returns a folder path corresponding to the packagename; setting capitalize_folder true returns folder names that are captialized
65 66 67 68 69 70 71 |
# 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 |
#get_slashed_package_name(packagename, capitalizefolder = false) ⇒ Object
Returns a namespace path with ‘' corresponding to the packagename; setting capitalizefolder true returns
names that are captialized
76 77 78 79 80 81 82 |
# 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 |
#is_urn_ns(ns) ⇒ Object
Checks if the uri starts with protocol schemes and returns true, else treats the namespace as a Uniform Resource Name
87 88 89 |
# File 'lib/genio/util/namespace_helper.rb', line 87 def is_urn_ns(ns) !ns.start_with?('http:','https:') end |
#lowercase_package(packagename) ⇒ Object
Lowercases parts of a package name eg: Paypal.Github.Payments.Sale is converted to paypal.github.payments.sale
51 52 53 |
# File 'lib/genio/util/namespace_helper.rb', line 51 def lowercase_package(packagename) packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase(:lower) } end |
#remove_tld_in_package(packagename) ⇒ Object
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
44 45 46 |
# 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 |