Class: Warg::Command::Name
- Inherits:
-
Object
- Object
- Warg::Command::Name
- Defined in:
- lib/warg.rb
Instance Attribute Summary collapse
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Class Method Summary collapse
Instance Method Summary collapse
- #console ⇒ Object
-
#initialize(class_name: nil, script_name: nil) ⇒ Name
constructor
A new instance of Name.
- #registry ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(class_name: nil, script_name: nil) ⇒ Name
Returns a new instance of Name.
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 |
# File 'lib/warg.rb', line 1690 def initialize(class_name: nil, script_name: nil) if class_name.nil? && script_name.nil? raise ArgumentError, "`script_name' or `class_name' must be specified" end if class_name @object = class_name @script = class_name.gsub("::", "/") @script.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1-\2') @script.gsub!(/([a-z\d])([A-Z])/, '\1-\2') @script.downcase! elsif script_name @script = script_name @object = script_name.gsub(/[a-z\d]*/) { |match| match.capitalize } @object.gsub!(/(?:_|-|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" } @object.gsub!("/", "::") end @cli = @script.tr("/", ":") end |
Instance Attribute Details
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
1686 1687 1688 |
# File 'lib/warg.rb', line 1686 def cli @cli end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
1687 1688 1689 |
# File 'lib/warg.rb', line 1687 def object @object end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
1688 1689 1690 |
# File 'lib/warg.rb', line 1688 def script @script end |
Class Method Details
.from_relative_script_path(path) ⇒ Object
1680 1681 1682 1683 1684 |
# File 'lib/warg.rb', line 1680 def self.from_relative_script_path(path) script_name = path.to_s.chomp File.extname(path) new(script_name: script_name.tr("_", "-")) end |
Instance Method Details
#console ⇒ Object
1713 1714 1715 |
# File 'lib/warg.rb', line 1713 def console "[#{cli}]" end |
#registry ⇒ Object
1717 1718 1719 |
# File 'lib/warg.rb', line 1717 def registry @cli end |
#to_s ⇒ Object
1721 1722 1723 |
# File 'lib/warg.rb', line 1721 def to_s @cli.dup end |