Sha256: 925ee21da9e370eefc525d6e6952c09772ec26d4c1635c5a143b3fcefca23031

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

# coding: utf-8
module References
  # This class let work internal names of authors of a fancy way.
  class Name
    include Comparable
    attr_reader :surnames, :names
    # Make a Name object
    # @param surnames [String] Take string with surnames of person of interest seperated with spaces.
    # @param names [String] Take string with names of person of interest seperated with spaces.
    def initialize(surnames, names)
      @surnames = surnames.split(" ")
      @names = names.split(" ")
    end
    # Define the comparasion of names, in this case is with the first surname.
    def <=>(other)
      other.surnames.first <=> @surnames.first
    end

    # Let convert a Name object in a human readable String in fancy way too.
    # @return [String]
    def to_s
      @surnames.first + ", " + (@names.map { |x| x[0].upcase }).join(". ") + ". "
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
referencess-0.1.0 lib/references/name.rb