Class: Obst::Notes
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(**opts) ⇒ Notes
constructor
A new instance of Notes.
Constructor Details
#initialize(**opts) ⇒ Notes
Returns a new instance of Notes.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/obst/notes.rb', line 7 def initialize(**opts) location = opts[:C] || '.' @notes = Enumerator.new do |enum| note_klass = Struct.new(:name, :dates, :tags, :refs) files = Dir.glob(File.join(location, '*.md')).map{|n| File.basename(n)}.to_set file_dates = Hash.new{ |h, k| h[k] = [] } GroupByDays.new(**opts).each do |log| log.file_changes.each do |name, op| file_dates[name] << log.time if files.include?(name) end end file_dates.each_pair do |file, dates| lines = File.foreach(File.join(location, file)) = lines.first&.scan(/#(\w+)/)&.flatten || [] refs = lines.each_with_object([]) do |line, arr| line.scan(/\[\[(.+?)\]\]/).flatten.each do |n| arr << n if files.include?("#{n}.md") end end enum.yield(note_klass.new(file, dates, , refs)) end end end |
Instance Method Details
#each(&block) ⇒ Object
34 35 36 |
# File 'lib/obst/notes.rb', line 34 def each(&block) @notes.each(&block) end |