Class: Chronograph::Timeline

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chronograph/timeline.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Timeline

Returns a new instance of Timeline.



8
9
10
11
12
13
14
15
16
# File 'lib/chronograph/timeline.rb', line 8

def initialize(&block)
	@people = []
	@events = []

          t = EventDSL.new
          t.instance_eval(&block)
          @people << t.people
          @events << t.events
end

Instance Method Details

#add(&block) ⇒ Object



18
19
20
21
22
23
# File 'lib/chronograph/timeline.rb', line 18

def add &block
    t = EventDSL.new
    t.instance_eval(&block)
    @people << t.people
    @event << t.events
end

#consolidateObject



37
38
39
40
41
# File 'lib/chronograph/timeline.rb', line 37

def consolidate
	t = []
	t << @events << @people.flatten.map { |x| x.events }
	return t.flatten.sort { |a, b| a.date <=> b.date }
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/chronograph/timeline.rb', line 25

def each(&block)
    consolidate.each(&block)
end

#event(name, date, desc) ⇒ Object



29
30
31
# File 'lib/chronograph/timeline.rb', line 29

def event(name, date, desc)
	@events << Event.new(name, date, desc)
end

#get_html_tableObject



47
48
49
50
51
52
53
54
# File 'lib/chronograph/timeline.rb', line 47

def get_html_table
#            warn "Warning, get_html_table has not tested"
	r = "<table>"
	consolidate.each do |x|
              r += x.to_table_html
	end
	r += "</table>"
end

#get_textObject



43
44
45
# File 'lib/chronograph/timeline.rb', line 43

def get_text
	consolidate.map { |x| "#{x.date}: #{x.name}, #{x.desc}" }.join("\n")
end

#todayObject



33
34
35
# File 'lib/chronograph/timeline.rb', line 33

def today
	event "Today", Date.today, "this day"
end