Class: Warg::Command::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/warg.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name: nil, script_name: nil) ⇒ Name

Returns a new instance of Name.



1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
# File 'lib/warg.rb', line 1821

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

#cliObject (readonly)

Returns the value of attribute cli.



1817
1818
1819
# File 'lib/warg.rb', line 1817

def cli
  @cli
end

#objectObject (readonly)

Returns the value of attribute object.



1818
1819
1820
# File 'lib/warg.rb', line 1818

def object
  @object
end

#scriptObject (readonly)

Returns the value of attribute script.



1819
1820
1821
# File 'lib/warg.rb', line 1819

def script
  @script
end

Class Method Details

.from_relative_script_path(path) ⇒ Object



1811
1812
1813
1814
1815
# File 'lib/warg.rb', line 1811

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

#consoleObject



1844
1845
1846
# File 'lib/warg.rb', line 1844

def console
  "[#{cli}]"
end

#registryObject



1848
1849
1850
# File 'lib/warg.rb', line 1848

def registry
  @cli
end

#to_sObject



1852
1853
1854
# File 'lib/warg.rb', line 1852

def to_s
  @cli.dup
end