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.



1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
# File 'lib/warg.rb', line 1780

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.



1776
1777
1778
# File 'lib/warg.rb', line 1776

def cli
  @cli
end

#objectObject (readonly)

Returns the value of attribute object.



1777
1778
1779
# File 'lib/warg.rb', line 1777

def object
  @object
end

#scriptObject (readonly)

Returns the value of attribute script.



1778
1779
1780
# File 'lib/warg.rb', line 1778

def script
  @script
end

Class Method Details

.from_relative_script_path(path) ⇒ Object



1770
1771
1772
1773
1774
# File 'lib/warg.rb', line 1770

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



1803
1804
1805
# File 'lib/warg.rb', line 1803

def console
  "[#{cli}]"
end

#registryObject



1807
1808
1809
# File 'lib/warg.rb', line 1807

def registry
  @cli
end

#to_sObject



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

def to_s
  @cli.dup
end