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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/topicz/repository.rb', line 58 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'] || {} @metadata = yaml['metadata'] || {} end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def aliases @aliases end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def category @category end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
56 57 58 |
# File 'lib/topicz/repository.rb', line 56 def title @title end |
Instance Method Details
#fullpath ⇒ Object
Full path to this topic on disk
90 91 92 |
# File 'lib/topicz/repository.rb', line 90 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.
80 81 82 83 84 85 86 87 |
# File 'lib/topicz/repository.rb', line 80 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
99 100 101 |
# File 'lib/topicz/repository.rb', line 99 def parents @parents.keys end |
#references ⇒ Object
List of unique topic IDs that this topic refers to.
95 96 97 |
# File 'lib/topicz/repository.rb', line 95 def references @parents.keys end |
#relations ⇒ Object
103 104 105 |
# File 'lib/topicz/repository.rb', line 103 def relations @relations.keys end |
#to_s ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/topicz/repository.rb', line 107 def to_s <<-EOS Topic '#{@id}' { title: '#{@title}', aliases: '#{@aliases}', category: '#{@category}', parents: #{@parents}, relations: #{@relations} } EOS end |