Class: Topicz::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/topicz/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aliasesObject (readonly)

Returns the value of attribute aliases.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def aliases
  @aliases
end

#categoryObject (readonly)

Returns the value of attribute category.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def category
  @category
end

#idObject (readonly)

Returns the value of attribute id.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def 
  @metadata
end

#pathObject (readonly)

Returns the value of attribute path.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



56
57
58
# File 'lib/topicz/repository.rb', line 56

def title
  @title
end

Instance Method Details

#fullpathObject

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

#parentsObject



99
100
101
# File 'lib/topicz/repository.rb', line 99

def parents
  @parents.keys
end

#referencesObject

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

#relationsObject



103
104
105
# File 'lib/topicz/repository.rb', line 103

def relations
  @relations.keys
end

#to_sObject



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