Class: References::Name

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/references/name.rb

Overview

This class let work internal names of authors of a fancy way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(surnames, names) ⇒ Name

Make a Name object

Parameters:

  • surnames (String)

    Take string with surnames of person of interest seperated with spaces.

  • names (String)

    Take string with names of person of interest seperated with spaces.



10
11
12
13
# File 'lib/references/name.rb', line 10

def initialize(surnames, names)
  @surnames = surnames.split(" ")
  @names = names.split(" ")
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



6
7
8
# File 'lib/references/name.rb', line 6

def names
  @names
end

#surnamesObject (readonly)

Returns the value of attribute surnames.



6
7
8
# File 'lib/references/name.rb', line 6

def surnames
  @surnames
end

Instance Method Details

#<=>(other) ⇒ Object

Define the comparasion of names, in this case is with the first surname.



15
16
17
# File 'lib/references/name.rb', line 15

def <=>(other)
  other.surnames.first <=> @surnames.first
end

#to_sString

Let convert a Name object in a human readable String in fancy way too.

Returns:

  • (String)


21
22
23
# File 'lib/references/name.rb', line 21

def to_s
  @surnames.first + ", " + (@names.map { |x| x[0].upcase }).join(". ") + ". "
end