Class: BoPeep::Command::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/bopeep.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.



1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
# File 'lib/bopeep.rb', line 1905

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.



1901
1902
1903
# File 'lib/bopeep.rb', line 1901

def cli
  @cli
end

#objectObject (readonly)

Returns the value of attribute object.



1902
1903
1904
# File 'lib/bopeep.rb', line 1902

def object
  @object
end

#scriptObject (readonly)

Returns the value of attribute script.



1903
1904
1905
# File 'lib/bopeep.rb', line 1903

def script
  @script
end

Class Method Details

.from_relative_script_path(path) ⇒ Object



1895
1896
1897
1898
1899
# File 'lib/bopeep.rb', line 1895

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



1928
1929
1930
# File 'lib/bopeep.rb', line 1928

def console
  "[#{cli}]"
end

#registryObject



1932
1933
1934
# File 'lib/bopeep.rb', line 1932

def registry
  @cli
end

#to_sObject



1936
1937
1938
# File 'lib/bopeep.rb', line 1936

def to_s
  @cli.dup
end