Class: Chronograph::Timeline
- Inherits:
-
Object
- Object
- Chronograph::Timeline
- Includes:
- Enumerable
- Defined in:
- lib/chronograph/timeline.rb
Instance Method Summary collapse
- #add(&block) ⇒ Object
- #consolidate ⇒ Object
- #each(&block) ⇒ Object
- #event(name, date, desc) ⇒ Object
- #get_html_table ⇒ Object
- #get_text ⇒ Object
-
#initialize(&block) ⇒ Timeline
constructor
A new instance of Timeline.
- #today ⇒ Object
Constructor Details
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 |
#consolidate ⇒ Object
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_table ⇒ Object
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_text ⇒ Object
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 |
#today ⇒ Object
33 34 35 |
# File 'lib/chronograph/timeline.rb', line 33 def today event "Today", Date.today, "this day" end |