Class: Database::Author

Inherits:
Struct
  • Object
show all
Defined in:
lib/database/author.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



6
7
8
# File 'lib/database/author.rb', line 6

def email
  @email
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/database/author.rb', line 6

def name
  @name
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



6
7
8
# File 'lib/database/author.rb', line 6

def time
  @time
end

Class Method Details

.parse(string) ⇒ Object



7
8
9
10
11
12
# File 'lib/database/author.rb', line 7

def self.parse(string)
  name, email, time = string.split(/<|>/).map(&:strip)
  time = Time.strptime(time, TIME_FORMAT)

  Author.new(name, email, time)
end

Instance Method Details

#readable_timeObject



18
19
20
# File 'lib/database/author.rb', line 18

def readable_time
  time.strftime("%a %b %-d %H:%M:%S %Y %z")
end

#short_dateObject



14
15
16
# File 'lib/database/author.rb', line 14

def short_date
  time.strftime("%Y-%m-%d")
end

#to_sObject



22
23
24
25
# File 'lib/database/author.rb', line 22

def to_s
  timestamp = time.strftime(TIME_FORMAT)
  "#{ name } <#{ email }> #{ timestamp }"
end