nitc :: Person :: defaultinit
# A contributor/author/etc.
#
# It comes from git or the metadata
#
# TODO get more things from github by using the email as a key
# "https://api.github.com/search/users?q={email}+in:email"
class Person
# The name. Eg "John Doe"
var name: String is writable
# The email, Eg "john.doe@example.com"
var email: nullable String is writable
# Some homepage. Eg "http://example.com/~jdoe"
var page: nullable String is writable
# Gravatar id
var gravatar: nullable String is lazy do
var email = self.email
if email == null then return null
return email.md5.to_lower
end
# The standard representation of a person.
#
# ~~~
# var jd = new Person("John Doe", "john.doe@example.com", "http://example.com/~jdoe")
# assert jd.to_s == "John Doe <john.doe@example.com> (http://example.com/~jdoe)"
# ~~~
#
# It can be used as the input of `parse`.
#
# ~~~
# var jd2 = new Person.parse(jd.to_s)
# assert jd2.to_s == jd.to_s
# ~~~
redef fun to_s
do
var res = name
var email = self.email
if email != null then res += " <{email}>"
var page = self.page
if page != null then res += " ({page})"
return res
end
# Crete a new person from its standard textual representation.
#
# ~~~
# var jd = new Person.parse("John Doe <john.doe@example.com> (http://example.com/~jdoe)")
# assert jd.name == "John Doe"
# assert jd.email == "john.doe@example.com"
# assert jd.page == "http://example.com/~jdoe"
# ~~~
#
# Emails and page are optional.
#
# ~~~
# var jd2 = new Person.parse("John Doe")
# assert jd2.name == "John Doe"
# assert jd2.email == null
# assert jd2.page == null
# ~~~
init parse(person: String)
do
var name = person
var email = null
var page = null
# Regular expressions are broken, need to investigate.
# So split manually.
#
#var re = "([^<(]*?)(<([^>]*?)>)?(\\((.*)\\))?".to_re
#var m = (person+" ").search(re)
#print "{person}: `{m or else "?"}` `{m[1] or else "?"}` `{m[3] or else "?"}` `{m[5] or else "?"}`"
do
var sp1 = person.split_once_on("<")
if sp1.length < 2 then
break
end
var sp2 = sp1.last.split_once_on(">")
if sp2.length < 2 then
break
end
name = sp1.first.trim
email = sp2.first.trim
var sp3 = sp2.last.split_once_on("(")
if sp3.length < 2 then
break
end
var sp4 = sp3.last.split_once_on(")")
if sp4.length < 2 then
break
end
page = sp4.first.trim
end
init(name, email, page)
end
end
src/catalog/catalog.nit:145,1--243,3