Sha256: 26be60e37352663385c4c02df5aba0eba32bc407f1126339007d545ca9c83db9

Contents?: true

Size: 699 Bytes

Versions: 4

Compression:

Stored size: 699 Bytes

Contents

module Apidoco
  # Parse a folder and find all the sub folders and files
  class FileParser
    attr_accessor :file, :parents

    def initialize(file, parents:)
      self.file = file
      self.parents = parents
    end

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

    def content
      @content ||= JSON.parse(File.read(file))
    rescue JSON::ParserError => e
      raise Apidoco::FileParseError.new file, e.message
    end

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apidoco-1.6.4 lib/apidoco/file_parser.rb
apidoco-1.6.3 lib/apidoco/file_parser.rb
apidoco-1.6.2 lib/apidoco/file_parser.rb
apidoco-1.6.1 lib/apidoco/file_parser.rb