Class: Chronograph::EventDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/chronograph/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventDSL

Returns a new instance of EventDSL.



7
8
9
10
# File 'lib/chronograph/dsl.rb', line 7

def initialize()
    @events = []
    @people = []
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



6
7
8
# File 'lib/chronograph/dsl.rb', line 6

def events
  @events
end

#peopleObject

Returns the value of attribute people.



6
7
8
# File 'lib/chronograph/dsl.rb', line 6

def people
  @people
end

Instance Method Details

#event(name, date, desc) ⇒ Object



13
14
15
16
# File 'lib/chronograph/dsl.rb', line 13

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

#group(name, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/chronograph/dsl.rb', line 53

def group name, &block
    events = []
    t = EventDSL.new
    t.instance_eval(&block) if block != nil
    events << t.events
    events << t.people.map { |x| x.events}
    events.flatten!
    events.each { |x| x.group = name}
    @events << events.flatten
end

#long_event(name, birth, death, desc, &block) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/chronograph/dsl.rb', line 31

def long_event(name, birth, death, desc, &block)
    birth = parse_date birth
    death = parse_date death
    t = EventDSL.new
    t.instance_eval(&block) if block != nil

    @people << LongEvent.new(name, birth, death, desc, *(t.events + t.people.map { |x| x.events }))
end

#parse_date(x) ⇒ Object



49
50
51
# File 'lib/chronograph/dsl.rb', line 49

def parse_date x
    x.is_a?(Integer) ? Date.new(x) : x
end

#person(name, birth, death, desc, &block) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/chronograph/dsl.rb', line 22

def person(name, birth, death, desc, &block)
    birth = parse_date birth
    death = parse_date death
    t = EventDSL.new
    t.instance_eval(&block) if block != nil
    
    @people << Person.new(name, birth, death, desc, *(t.events + t.people.map { |x| x.events })) # TODO: this sort of combines the events and the people. Problem?
end

#todayObject



18
19
20
# File 'lib/chronograph/dsl.rb', line 18

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

#war(name, birth, death, desc, &block) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/chronograph/dsl.rb', line 40

def war(name, birth, death, desc, &block)
    birth = parse_date birth
    death = parse_date death
    t = EventDSL.new
    t.instance_eval(&block) if block != nil

    @people << War.new(name, birth, death, desc, *(t.events + t.people.map { |x| x.events }))
end