Class: Rucoa::Yard::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/rucoa/yard/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Type

Returns a new instance of Type.

Parameters:

  • value (String)


7
8
9
# File 'lib/rucoa/yard/type.rb', line 7

def initialize(value)
  @value = value
end

Instance Method Details

#to_rucoa_typeString

Examples:

scrubs “Array<String>” to “Array”

yard_type = Rucoa::Yard::Type.new(
  'Array<String>'
)
expect(yard_type.to_rucoa_type).to eq('Array')

scrubs “Array(String, Integer)” to “Array”

yard_type = Rucoa::Yard::Type.new(
  'Array(String, Integer)'
)
expect(yard_type.to_rucoa_type).to eq('Array')

scrubs “::Array” to “Array”

yard_type = Rucoa::Yard::Type.new(
  '::Array'
)
expect(yard_type.to_rucoa_type).to eq('Array')

scrubs “Hash=> Object” to “Hash”

yard_type = Rucoa::Yard::Type.new(
  'Hash{Symbol => Object}'
)
expect(yard_type.to_rucoa_type).to eq('Hash')

scrubs “Array<Array<Integer>>” to “Array”

yard_type = Rucoa::Yard::Type.new(
  'Array<Array<Integer>>'
)
expect(yard_type.to_rucoa_type).to eq('Array')

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/rucoa/yard/type.rb', line 37

def to_rucoa_type
  @value
    .delete_prefix('::')
    .gsub(/<.+>/, '')
    .gsub(/\{.+\}/, '')
    .gsub(/\(.+\)/, '')
end