class Slaw::Grammars::Counters
Public Class Methods
clean(num)
click to toggle source
Clean a <num> value for use in an eId See docs.oasis-open.org/legaldocml/akn-nc/v1.0/os/akn-nc-v1.0-os.html#_Toc531692306
βThe number part of the identifiers of such elements corresponds to the stripping of all final punctuation, meaningless separations as well as redundant characters in the content of the <num> element. The representation is case-sensitive.β
Our algorithm is:
-
strip all leading and trailing whitespace and punctuation (using the unicode punctuation blocks)
-
strip all whitespace
-
replace all remaining punctuation with a hyphen.
The General Punctuation block is u2000-u206F, and the Supplemental Punctuation block is u2E00-u2E7F.
(i) -> i 1.2. -> 1-2 β2.3β -> 2-3 3a bis -> 3abis
# File lib/slaw/grammars/counters.rb, line 43 def self.clean(num) # leading whitespace and punctuation num = num.gsub(/^[\s\u{2000}-\u{206f}\u{2e00}-\u{2e7f}!"#$%&'()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/, '') # trailing whitespace and punctuation num.gsub!(/[\s\u{2000}-\u{206f}\u{2e00}-\u{2e7f}!"#$%&'()*+,\-.\/:;<=>?@\[\]^_`{|}~]+$/, '') # whitespace num.gsub!(/\s/, '') # remaining punctuation to a hyphen num.gsub!(/[\u{2000}-\u{206f}\u{2e00}-\u{2e7f}!"#$%&'()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/, '-') num end
counters()
click to toggle source
# File lib/slaw/grammars/counters.rb, line 16 def self.counters @@counters end
reset!()
click to toggle source
# File lib/slaw/grammars/counters.rb, line 20 def self.reset! @@counters.clear end