class DNote::NotesCollection

Notes Collection

This class contains a collection of Note objects and can group them in several ways.

Attributes

notes[R]

Array of notes.

Public Class Methods

new(notes) click to toggle source
# File lib/dnote/notes_collection.rb, line 12
def initialize(notes)
  @notes = notes
end

Public Instance Methods

by_file() click to toggle source

Organize notes into a hash with filename for keys.

# File lib/dnote/notes_collection.rb, line 47
def by_file
  @by_file ||= notes.group_by(&:file)
end
by_file_label() click to toggle source

Organize notes into a hash with filenames for keys, followed by a hash with labels for keys.

# File lib/dnote/notes_collection.rb, line 59
def by_file_label
  @by_file_label ||= by_file.transform_values { |notes| notes.group_by(&:label) }
end
by_label() click to toggle source

Organize notes into a hash with labels for keys.

# File lib/dnote/notes_collection.rb, line 42
def by_label
  @by_label ||= notes.group_by(&:label)
end
by_label_file() click to toggle source

Organize notes into a hash with labels for keys, followed by a hash with filename for keys.

# File lib/dnote/notes_collection.rb, line 53
def by_label_file
  @by_label_file ||= by_label.transform_values { |notes| notes.group_by(&:file) }
end
counts() click to toggle source

Notes counts by label.

# File lib/dnote/notes_collection.rb, line 20
def counts
  @counts ||=
    begin
      h = {}
      by_label.each do |label, notes|
        h[label] = notes.size
      end
      h
    end
end
each(&block) click to toggle source

Iterate through notes.

# File lib/dnote/notes_collection.rb, line 32
def each(&block)
  notes.each(&block)
end
empty?() click to toggle source

No notes?

# File lib/dnote/notes_collection.rb, line 37
def empty?
  notes.empty?
end
to_a() click to toggle source

Convert to an array of hashes.

# File lib/dnote/notes_collection.rb, line 64
def to_a
  notes.map(&:to_h)
end
to_h() click to toggle source

Same as by_label.

# File lib/dnote/notes_collection.rb, line 69
def to_h
  by_label
end