mirror of https://github.com/freeCodeCamp/devdocs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
896 B
46 lines
896 B
# frozen_string_literal: true
|
|
|
|
module Docs
|
|
class Entry
|
|
class Invalid < StandardError; end
|
|
|
|
attr_accessor :name, :type, :path
|
|
|
|
def initialize(name = nil, path = nil, type = nil)
|
|
self.name = name
|
|
self.path = path
|
|
self.type = type
|
|
|
|
unless root?
|
|
raise Invalid, 'missing name' if !name || name.empty?
|
|
raise Invalid, 'missing path' if !path || path.empty?
|
|
raise Invalid, 'missing type' if !type || type.empty?
|
|
end
|
|
end
|
|
|
|
def ==(other)
|
|
other.name == name && other.path == path && other.type == type
|
|
end
|
|
|
|
def <=>(other)
|
|
name.to_s.casecmp(other.name.to_s)
|
|
end
|
|
|
|
def name=(value)
|
|
@name = value.try :strip
|
|
end
|
|
|
|
def type=(value)
|
|
@type = value.try :strip
|
|
end
|
|
|
|
def root?
|
|
path == 'index'
|
|
end
|
|
|
|
def as_json
|
|
{ name: name, path: path, type: type }
|
|
end
|
|
end
|
|
end
|