Class: Jazzy::SourceDeclaration::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/source_declaration/type.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

TYPES =
{
  'source.lang.swift.decl.function.method.class' => {
    jazzy: 'Class Method',
    dash: 'Method',
  }.freeze,
  'source.lang.swift.decl.var.class' => {
    jazzy: 'Class Variable',
    dash: 'Variable',
  }.freeze,
  'source.lang.swift.decl.class' => {
    jazzy: 'Class',
    dash: 'Class',
  }.freeze,
  'source.lang.swift.decl.function.constructor' => {
    jazzy: 'Constructor',
    dash: 'Constructor',
  }.freeze,
  'source.lang.swift.decl.function.destructor' => {
    jazzy: 'Destructor',
    dash: 'Method',
  }.freeze,
  'source.lang.swift.decl.var.global' => {
    jazzy: 'Global Variable',
    dash: 'Global',
  }.freeze,
  'source.lang.swift.decl.enumelement' => {
    jazzy: 'Enum Element',
    dash: 'Element',
  }.freeze,
  'source.lang.swift.decl.enum' => {
    jazzy: 'Enum',
    dash: 'Enum',
  }.freeze,
  'source.lang.swift.decl.extension' => {
    jazzy: 'Extension',
    dash: 'Extension',
  }.freeze,
  'source.lang.swift.decl.function.free' => {
    jazzy: 'Function',
    dash: 'Function',
  }.freeze,
  'source.lang.swift.decl.function.method.instance' => {
    jazzy: 'Instance Method',
    dash: 'Method',
  }.freeze,
  'source.lang.swift.decl.var.instance' => {
    jazzy: 'Instance Variable',
    dash: 'Property',
  }.freeze,
  'source.lang.swift.decl.var.local' => {
    jazzy: 'Local Variable',
    dash: 'Variable',
  }.freeze,
  'source.lang.swift.decl.var.parameter' => {
    jazzy: 'Parameter',
    dash: 'Parameter',
  }.freeze,
  'source.lang.swift.decl.protocol' => {
    jazzy: 'Protocol',
    dash: 'Protocol',
  }.freeze,
  'source.lang.swift.decl.function.method.static' => {
    jazzy: 'Static Method',
    dash: 'Method',
  }.freeze,
  'source.lang.swift.decl.var.static' => {
    jazzy: 'Static Variable',
    dash: 'Variable',
  }.freeze,
  'source.lang.swift.decl.struct' => {
    jazzy: 'Struct',
    dash: 'Struct',
  }.freeze,
  'source.lang.swift.decl.function.subscript' => {
    jazzy: 'Subscript',
    dash: 'Method',
  }.freeze,
  'source.lang.swift.decl.typealias' => {
    jazzy: 'Typealias',
    dash: 'Alias',
  }.freeze,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ Type

Returns a new instance of Type.



13
14
15
16
# File 'lib/jazzy/source_declaration/type.rb', line 13

def initialize(kind)
  @kind = kind
  @type = TYPES[kind]
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



11
12
13
# File 'lib/jazzy/source_declaration/type.rb', line 11

def kind
  @kind
end

Class Method Details

.allObject



7
8
9
# File 'lib/jazzy/source_declaration/type.rb', line 7

def self.all
  TYPES.keys.map { |k| new(k) }
end

.overviewObject



49
50
51
# File 'lib/jazzy/source_declaration/type.rb', line 49

def self.overview
  Type.new('Overview')
end

Instance Method Details

#==(other) ⇒ Object



58
59
60
# File 'lib/jazzy/source_declaration/type.rb', line 58

def ==(other)
  other && kind == other.kind
end

#dash_typeObject



18
19
20
# File 'lib/jazzy/source_declaration/type.rb', line 18

def dash_type
  @type && @type[:dash]
end

#declaration?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/jazzy/source_declaration/type.rb', line 38

def declaration?
  kind =~ /^source\.lang\.swift\.decl\..*/
end

#equalsObject



57
# File 'lib/jazzy/source_declaration/type.rb', line 57

alias_method :equals, :==

#hashObject



53
54
55
# File 'lib/jazzy/source_declaration/type.rb', line 53

def hash
  kind.hash
end

#mark?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/jazzy/source_declaration/type.rb', line 30

def mark?
  kind == 'source.lang.swift.syntaxtype.comment.mark'
end

#nameObject



22
23
24
# File 'lib/jazzy/source_declaration/type.rb', line 22

def name
  @type && @type[:jazzy]
end

#param?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/jazzy/source_declaration/type.rb', line 42

def param?
  # SourceKit strangely categorizes initializer parameters as local
  # variables, so both kinds represent a parameter in jazzy.
  kind == 'source.lang.swift.decl.var.parameter' ||
    kind == 'source.lang.swift.decl.var.local'
end

#plural_nameObject



26
27
28
# File 'lib/jazzy/source_declaration/type.rb', line 26

def plural_name
  name.pluralize
end

#should_document?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/jazzy/source_declaration/type.rb', line 34

def should_document?
  declaration? && !param?
end