Class: Ssource::Source::RootObject
- Inherits:
-
Object
- Object
- Ssource::Source::RootObject
- Extended by:
- Forwardable
- Defined in:
- lib/ssource/source/root_object.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Class Method Summary collapse
Instance Method Summary collapse
- #classes ⇒ Object
- #extensions ⇒ Object
- #functions ⇒ Object
-
#initialize(file) ⇒ RootObject
constructor
A new instance of RootObject.
- #pretty_print ⇒ Object
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
#elements ⇒ Object (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
#classes ⇒ Object
29 30 31 |
# File 'lib/ssource/source/root_object.rb', line 29 def classes elements.select { |e| e.is_a? Klass } end |
#extensions ⇒ Object
33 34 35 |
# File 'lib/ssource/source/root_object.rb', line 33 def extensions elements.select { |e| e.is_a? Extension } end |
#functions ⇒ Object
37 38 39 |
# File 'lib/ssource/source/root_object.rb', line 37 def functions elements.select { |e| e.is_a? Method } end |
#pretty_print ⇒ Object
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 |