Class: Chronograph::Person

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

Direct Known Subclasses

LongEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, birth, death, desc, *events) ⇒ Person

Returns a new instance of Person.

Raises:

  • (TypeError)


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/chronograph/person.rb', line 4

def initialize(name, birth, death, desc, *events)
    raise TypeError.new("name has to be a name or symbol") unless name.is_a?(String) || name.is_a?(Symbol)
    raise TypeError.new("birth and death must be a date") unless birth.is_a?(Date) && death.is_a?(Date)
    
    raise TypeError.new("desc must be a string") unless desc.is_a? String
    
    @name = name
    @birth = birth
    @death = death
    @desc = desc
    @events = events
end

Instance Attribute Details

#birthObject

Returns the value of attribute birth



2
3
4
# File 'lib/chronograph/person.rb', line 2

def birth
  @birth
end

#deathObject

Returns the value of attribute death



2
3
4
# File 'lib/chronograph/person.rb', line 2

def death
  @death
end

#descObject

Returns the value of attribute desc



2
3
4
# File 'lib/chronograph/person.rb', line 2

def desc
  @desc
end

#eventsObject

Returns the value of attribute events



2
3
4
# File 'lib/chronograph/person.rb', line 2

def events
  @events
end

#nameObject

Returns the value of attribute name



2
3
4
# File 'lib/chronograph/person.rb', line 2

def name
  @name
end

Instance Method Details

#begining_eventObject



21
22
23
# File 'lib/chronograph/person.rb', line 21

def begining_event
    Event.new("Birth of #{name}", birth, "#{name} is born. #{@desc}")
end

#ending_eventObject



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

def ending_event
     Event.new("Death of #{name}", death, "#{name} dies. #{@desc}")
end