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

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

#aliasesObject (readonly)

Returns the value of attribute aliases.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def aliases
  @aliases
end

#categoryObject (readonly)

Returns the value of attribute category.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def category
  @category
end

#idObject (readonly)

Returns the value of attribute id.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def 
  
end

#pathObject (readonly)

Returns the value of attribute path.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



54
55
56
# File 'lib/topicz/repository.rb', line 54

def title
  @title
end

Instance Method Details

#fullpathObject

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

#parentsObject



97
98
99
# File 'lib/topicz/repository.rb', line 97

def parents
  @parents.keys
end

#referencesObject

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

#relationsObject



101
102
103
# File 'lib/topicz/repository.rb', line 101

def relations
  @relations.keys
end

#to_sObject



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"