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
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.message
end

#idObject



21
22
23
# File 'lib/apidoco/file_parser.rb', line 21

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

#published?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/apidoco/file_parser.rb', line 25

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

#sort_orderObject



29
30
31
# File 'lib/apidoco/file_parser.rb', line 29

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