Class: Apidoco::FileParser
- Inherits:
-
Object
- Object
- Apidoco::FileParser
- Defined in:
- lib/apidoco/file_parser.rb
Overview
Parse a folder and find all the sub folders and files
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#parents ⇒ Object
Returns the value of attribute parents.
Instance Method Summary collapse
- #as_json ⇒ Object
- #content ⇒ Object
- #id ⇒ Object
-
#initialize(file, parents:) ⇒ FileParser
constructor
A new instance of FileParser.
- #published? ⇒ Boolean
- #sort_order ⇒ Object
Constructor Details
#initialize(file, parents:) ⇒ FileParser
Returns a new instance of FileParser.
6 7 8 9 |
# File 'lib/apidoco/file_parser.rb', line 6 def initialize(file, parents:) self.file = file self.parents = parents end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/apidoco/file_parser.rb', line 4 def file @file end |
#parents ⇒ Object
Returns the value of attribute parents.
4 5 6 |
# File 'lib/apidoco/file_parser.rb', line 4 def parents @parents end |
Instance Method Details
#as_json ⇒ Object
11 12 13 |
# File 'lib/apidoco/file_parser.rb', line 11 def as_json content.merge(parents: parents, id: id) end |
#content ⇒ Object
15 16 17 18 19 |
# File 'lib/apidoco/file_parser.rb', line 15 def content @content ||= JSON.parse(File.read(file)) rescue JSON::ParserError => e raise Apidoco::FileParseError.new file, e. end |
#id ⇒ Object
21 22 23 |
# File 'lib/apidoco/file_parser.rb', line 21 def id parents.push(content['name']).join('-').downcase.delete(' ') end |
#published? ⇒ Boolean
25 26 27 |
# File 'lib/apidoco/file_parser.rb', line 25 def published? content['published'].nil? || content['published'] end |
#sort_order ⇒ Object
29 30 31 |
# File 'lib/apidoco/file_parser.rb', line 29 def sort_order content['sort_order'] || 999 end |