entry.rb 609 B

1234567891011121314151617181920212223242526272829303132333435
  1. module Docs
  2. class Entry
  3. attr_accessor :name, :type, :path
  4. def initialize(name = nil, path = nil, type = nil)
  5. self.name = name
  6. self.path = path
  7. self.type = type
  8. end
  9. def ==(other)
  10. other.name == name && other.path == path && other.type == type
  11. end
  12. def <=>(other)
  13. name.to_s.casecmp(other.name.to_s)
  14. end
  15. def name=(value)
  16. @name = value.try :strip
  17. end
  18. def type=(value)
  19. @type = value.try :strip
  20. end
  21. def root?
  22. path == 'index'
  23. end
  24. def as_json
  25. { name: name, path: path, type: type }
  26. end
  27. end
  28. end