Class: Apidoco::FolderParser
- Inherits:
-
Object
- Object
- Apidoco::FolderParser
- Defined in:
- lib/apidoco/folder_parser.rb
Overview
Parse a folder and find all the sub folders and files
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#parents ⇒ Object
Returns the value of attribute parents.
Instance Method Summary collapse
- #as_json ⇒ Object
- #basename ⇒ Object
- #children ⇒ Object
-
#initialize(directory, parents: []) ⇒ FolderParser
constructor
A new instance of FolderParser.
- #published? ⇒ Boolean
- #sort_order ⇒ Object
Constructor Details
#initialize(directory, parents: []) ⇒ FolderParser
Returns a new instance of FolderParser.
6 7 8 9 |
# File 'lib/apidoco/folder_parser.rb', line 6 def initialize(directory, parents: []) self.directory = directory self.parents = parents end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
4 5 6 |
# File 'lib/apidoco/folder_parser.rb', line 4 def directory @directory end |
#parents ⇒ Object
Returns the value of attribute parents.
4 5 6 |
# File 'lib/apidoco/folder_parser.rb', line 4 def parents @parents end |
Instance Method Details
#as_json ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/apidoco/folder_parser.rb', line 11 def as_json { is_folder: true, name: basename, children: children.select(&:published?).yield_self(&method(:sorter)).map(&:as_json) } end |
#basename ⇒ Object
19 20 21 |
# File 'lib/apidoco/folder_parser.rb', line 19 def basename directory.basename.to_s.titleize end |
#children ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/apidoco/folder_parser.rb', line 23 def children directory.children.map do |child| hierrarchy = parents + [basename] if child.directory? Apidoco::FolderParser.new(child, parents: hierrarchy) else Apidoco::FileParser.new(child, parents: hierrarchy) end end end |
#published? ⇒ Boolean
34 35 36 |
# File 'lib/apidoco/folder_parser.rb', line 34 def published? true end |
#sort_order ⇒ Object
38 39 40 |
# File 'lib/apidoco/folder_parser.rb', line 38 def sort_order basename end |