Class: Ssource::Source::RootObject

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ssource/source/root_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ RootObject

Returns a new instance of RootObject.



11
12
13
14
# File 'lib/ssource/source/root_object.rb', line 11

def initialize(file)
  elements = Ssource::SourceKitten.structure file
  @elements = elements.map { |element| Factory.build element }
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



9
10
11
# File 'lib/ssource/source/root_object.rb', line 9

def elements
  @elements
end

Class Method Details

.from(file) ⇒ Object



18
19
20
# File 'lib/ssource/source/root_object.rb', line 18

def self.from(file)
  Root.new(file)
end

Instance Method Details

#classesObject



29
30
31
# File 'lib/ssource/source/root_object.rb', line 29

def classes
  elements.select { |e| e.is_a? Klass }
end

#extensionsObject



33
34
35
# File 'lib/ssource/source/root_object.rb', line 33

def extensions
  elements.select { |e| e.is_a? Extension }
end

#functionsObject



37
38
39
# File 'lib/ssource/source/root_object.rb', line 37

def functions
  elements.select { |e| e.is_a? Method }
end

#pretty_printObject



22
23
24
25
26
27
# File 'lib/ssource/source/root_object.rb', line 22

def pretty_print
  %i[classes functions extensions].each_with_object({}) do |instance_variable, hash|
    collections = send(instance_variable).map(&:pretty_print)
    hash[instance_variable.to_s.capitalize] = collections unless collections.empty?
  end
end