Class: Hexx::CLI::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/hexx/cli/name.rb

Overview

Decorates a string with conventional names

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initialize(string) ⇒ Hexx::CLI::Name

Constructs the parser object

Examples:

Hexx::CLI::Name.new "MyGem::MyClass.methods.chain"

Parameters:

  • string (#to_s)

    The string to be parsed

Returns:



22
23
24
# File 'lib/hexx/cli/name.rb', line 22

def initialize(string)
  @list = string.to_s.snake_case.gsub(/\:{2}|-/, "/").split(".")
end

Instance Method Details

#constString

Returns the name as a last part of constant

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.const
# => "PantherTiger.bite"

Returns:

  • (String)


100
101
102
# File 'lib/hexx/cli/name.rb', line 100

def const
  @const ||= [camels.last, method].compact.join(".")
end

#fileString

Returns the dashes-delimited name

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.file
# => "cats-wildcats-jaguars-panther_tiger.bite"

Returns:

  • (String)


61
62
63
# File 'lib/hexx/cli/name.rb', line 61

def file
  @file ||= [snakes.join("-"), method].compact.join(".")
end

#itemString

Returns the last part of the singular name

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.item
# => "panther_tiger"

Returns:

  • (String)


35
36
37
# File 'lib/hexx/cli/name.rb', line 35

def item
  @item ||= snakes.last.to_s.singular
end

#itemsString

Returns the last part of the plural name

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.items
# => "panther_tigers"

Returns:

  • (String)


48
49
50
# File 'lib/hexx/cli/name.rb', line 48

def items
  @items ||= item.plural
end

#namespacesArray<String>

Returns the array of namespaces (module names) for the constant

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.namespaces
# => ["Cats", "Wildcats", "Jaguars"]

Returns:

  • (Array<String>)


113
114
115
# File 'lib/hexx/cli/name.rb', line 113

def namespaces
  @namespaces ||= camels[0..-2]
end

#new(string) ⇒ Hexx::CLI::Name

Constructs the parser object

Examples:

Hexx::CLI::Name.new "MyGem::MyClass.methods.chain"

Parameters:

  • string (#to_s)

    The string to be parsed

Returns:



22
23
24
# File 'lib/hexx/cli/name.rb', line 22

def initialize(string)
  @list = string.to_s.snake_case.gsub(/\:{2}|-/, "/").split(".")
end

#pathString

Returns the slash-delimited name

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.path
# => "cats/wildcats/jaguars/panther_tiger/bite"

Returns:

  • (String)


74
75
76
# File 'lib/hexx/cli/name.rb', line 74

def path
  @path ||= [snakes.join("/"), method].compact.join(".")
end

#typeString

Returns the name as a full constant

Examples:

source = "cats-wildcats/jaguars::PantherTiger.bite"
name = Hexx::CLI::Name.new(source)
name.type
# => "Cats::Wildcats::Jaguars::PantherTiger.bite"

Returns:

  • (String)


87
88
89
# File 'lib/hexx/cli/name.rb', line 87

def type
  @type ||= [camels.join("::"), method].compact.join(".")
end