Class: References::Name
- Inherits:
-
Object
- Object
- References::Name
- 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
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#surnames ⇒ Object
readonly
Returns the value of attribute surnames.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Define the comparasion of names, in this case is with the first surname.
-
#initialize(surnames, names) ⇒ Name
constructor
Make a Name object.
-
#to_s ⇒ String
Let convert a Name object in a human readable String in fancy way too.
Constructor Details
#initialize(surnames, names) ⇒ Name
Make a Name object
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
#names ⇒ Object (readonly)
Returns the value of attribute names.
6 7 8 |
# File 'lib/references/name.rb', line 6 def names @names end |
#surnames ⇒ Object (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_s ⇒ String
Let convert a Name object in a human readable String in fancy way too.
21 22 23 |
# File 'lib/references/name.rb', line 21 def to_s @surnames.first + ", " + (@names.map { |x| x[0].upcase }).join(". ") + ". " end |