Class: Ssource::Source::Klass
Instance Attribute Summary collapse
Attributes inherited from Element
#accessibility, #body_length, #body_offset, #elements, #kind, #length, #name, #name_length, #name_offset, #offset
Instance Method Summary
collapse
Methods inherited from Element
#display_name
Constructor Details
#initialize(json) ⇒ Klass
Returns a new instance of Klass.
12
13
14
15
16
17
|
# File 'lib/ssource/source/klass.rb', line 12
def initialize(json)
super
inherited_types = json.fetch('inheritedtypes', []).map { |hash| hash['key.name'] }
@superklass = inherited_types.first
@protocols = inherited_types[1..-1] || []
end
|
Instance Attribute Details
#protocols ⇒ Object
Returns the value of attribute protocols.
10
11
12
|
# File 'lib/ssource/source/klass.rb', line 10
def protocols
@protocols
end
|
#superklass ⇒ Object
Returns the value of attribute superklass.
9
10
11
|
# File 'lib/ssource/source/klass.rb', line 9
def superklass
@superklass
end
|
Instance Method Details
#class_methods ⇒ Object
31
32
33
|
# File 'lib/ssource/source/klass.rb', line 31
def class_methods
methods.select(&:class?)
end
|
#elements_variables ⇒ Object
54
55
56
|
# File 'lib/ssource/source/klass.rb', line 54
def elements_variables
%i[variables instance_methods static_methods class_methods]
end
|
#instance_methods ⇒ Object
23
24
25
|
# File 'lib/ssource/source/klass.rb', line 23
def instance_methods
methods.select(&:instance?)
end
|
#methods ⇒ Object
19
20
21
|
# File 'lib/ssource/source/klass.rb', line 19
def methods
elements.select { |element| element.is_a? Method }
end
|
#pretty_print ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/ssource/source/klass.rb', line 46
def pretty_print
result = elements_variables.each_with_object({}) do |method, hash|
collections = send(method).map(&:pretty_print)
hash[method.to_s.capitalize] = collections unless collections.empty?
end
{ display_name => result }
end
|
#static_methods ⇒ Object
27
28
29
|
# File 'lib/ssource/source/klass.rb', line 27
def static_methods
methods.select(&:static?)
end
|
#to_hash ⇒ Object
39
40
41
42
43
44
|
# File 'lib/ssource/source/klass.rb', line 39
def to_hash
elements_variables.each_with_object(super) do |method, hash|
collections = send(method).map(&:to_hash)
hash[instance_variable.to_s.capitalize] = collections unless collections.empty?
end
end
|
#variables ⇒ Object
35
36
37
|
# File 'lib/ssource/source/klass.rb', line 35
def variables
elements.select { |element| element.is_a? Variable }
end
|