Class: Apidoco::FileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/apidoco/file_parser.rb

Overview

Parse a folder and find all the sub folders and files

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject

Returns the value of attribute file.



4
5
6
# File 'lib/apidoco/file_parser.rb', line 4

def file
  @file
end

#parentsObject

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_jsonObject



11
12
13
# File 'lib/apidoco/file_parser.rb', line 11

def as_json
  content.merge(parents: parents, id: id)
end

#contentObject



15
16
17
# File 'lib/apidoco/file_parser.rb', line 15

def content
  JSON.parse(File.read(file))
end

#idObject



19
20
21
# File 'lib/apidoco/file_parser.rb', line 19

def id
  parents.push(content['name']).join('-').downcase.delete(' ')
end

#published?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/apidoco/file_parser.rb', line 23

def published?
  content['published'].nil? || content['published']
end

#sort_orderObject



27
28
29
# File 'lib/apidoco/file_parser.rb', line 27

def sort_order
  content['sort_order'] || 999
end