-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-155 lsid model spec - test that #identifier is validly formatted. …
…Model and spec.
- Loading branch information
Showing
4 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
class Identifier::Global::Lsid < Identifier::Global | ||
# urn:lsid:Orthoptera.speciesfile.org:TaxonName:1 | ||
=begin | ||
• "URN" | ||
• "LSID" | ||
• authority identification | ||
• namespace identification | ||
• object identification | ||
• optionally: revision identification. If revision field is omitted then the trailing colon is also omitted. | ||
=end | ||
validate :using_lsid_class | ||
|
||
def using_lsid_class | ||
retval = true | ||
unless identifier.nil? | ||
lsid = identifier | ||
lsid = identifier.split(':') | ||
# this is a test of http://rubular.com/regexes/13295 | ||
/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)/ =~ identifier | ||
|
||
errors.add(:identifier, "'#{identifier}' is not a valid LSID.") | ||
return false | ||
unless lsid.length.between?(5, 6) | ||
unless lsid[0].upcase == 'URN' and lsid[1].upcase == 'LSID' | ||
errors.add(:identifier, "'#{identifier}' is not a valid LSID.") | ||
retval = false | ||
end | ||
end | ||
end | ||
return retval | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters