Class: OrgMode::Reporters::Agenda

Inherits:
Object
  • Object
show all
Defined in:
lib/org_mode/reporters/agenda.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_collection) ⇒ Agenda

Returns a new instance of Agenda.



8
9
10
# File 'lib/org_mode/reporters/agenda.rb', line 8

def initialize(file_collection)
  @file_collection = file_collection 
end

Instance Attribute Details

#file_collectionObject

Returns the value of attribute file_collection.



7
8
9
# File 'lib/org_mode/reporters/agenda.rb', line 7

def file_collection
  @file_collection
end

Instance Method Details

#open_nodes_grouped_by_dayObject

Public: returns open nodes grouped by day ordered by date

Returns an Array of Hash-es like

{:date => ā€˜%Y-%m-%dā€™, :nodes => [{ .. }]}

ready to be used by fe Mustache



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/org_mode/reporters/agenda.rb', line 18

def open_nodes_grouped_by_day
  # Get all nodes from all files
  # extract scheduled items which are not done
  # discard all DONE items
  nodes_of_interest = file_collection.scheduled_nodes.select(&:open?)

  # group them by date
  noi_per_day = nodes_of_interest.group_by { |noi| noi.date.strftime('%Y-%m-%d') }
 
  # build a nice orderd struct
  noi_per_day.keys.sort.map do |date|
    { :date => date, :nodes => noi_per_day[date].map { |n| node_to_hash(n) } }
  end.map(&:to_ostruct)

end