Class: Topicz::Topic
- Inherits:
-
Object
- Object
- Topicz::Topic
- Defined in:
- lib/topicz/repository.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#fullpath ⇒ Object
Full path to this topic on disk.
-
#initialize(root, path) ⇒ Topic
constructor
A new instance of Topic.
-
#matches(filter) ⇒ Object
Checks whether this topic’s title or one of its aliases matches the filter The filter may be
nil, in which case it is said to match. - #parents ⇒ Object
-
#references ⇒ Object
List of unique topic IDs that this topic refers to.
- #relations ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(root, path) ⇒ Topic
Returns a new instance of Topic.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/topicz/repository.rb', line 56 def initialize(root, path) @root = root @path = path descriptor = File.join(@root, @path, 'topic.yaml') yaml = if File.exist?(descriptor) YAML.load_file(descriptor) else {} end @id = yaml['id'] || create_id(path) @category = yaml['category'] || 'none' @title = yaml['title'] || @path @aliases = yaml['aliases'] || [] @parents = yaml['depends on'] || {} @relations = yaml['relates to'] || {} = yaml['metadata'] || {} end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def aliases @aliases end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def category @category end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
54 55 56 |
# File 'lib/topicz/repository.rb', line 54 def title @title end |
Instance Method Details
#fullpath ⇒ Object
Full path to this topic on disk
88 89 90 |
# File 'lib/topicz/repository.rb', line 88 def fullpath File.join(@root, @path) end |
#matches(filter) ⇒ Object
Checks whether this topic’s title or one of its aliases matches the filter The filter may be nil, in which case it is said to match.
78 79 80 81 82 83 84 85 |
# File 'lib/topicz/repository.rb', line 78 def matches(filter) return true unless filter filter = filter.downcase @title.downcase.include?(filter) || @id.downcase.include?(filter) || !(@aliases.select { |a| a.downcase.include?(filter) }.empty?) || @path.downcase.include?(filter) end |
#parents ⇒ Object
97 98 99 |
# File 'lib/topicz/repository.rb', line 97 def parents @parents.keys end |
#references ⇒ Object
List of unique topic IDs that this topic refers to.
93 94 95 |
# File 'lib/topicz/repository.rb', line 93 def references @parents.keys end |
#relations ⇒ Object
101 102 103 |
# File 'lib/topicz/repository.rb', line 101 def relations @relations.keys end |
#to_s ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/topicz/repository.rb', line 105 def to_s "Topic '\#{@id}' {\n title: '\#{@title}',\n aliases: '\#{@aliases}',\n category: '\#{@category}',\n parents: \#{@parents},\n relations: \#{@relations}\n}\n EOS\nend\n" |