Class: Tankobon::SanitizeTransform
- Defined in:
- lib/tankobon/transform.rb
Instance Method Summary collapse
-
#initialize(padding = 5) ⇒ SanitizeTransform
constructor
A new instance of SanitizeTransform.
- #pad(num) ⇒ Object
- #transform(input) ⇒ Object
Methods inherited from Transform
Constructor Details
#initialize(padding = 5) ⇒ SanitizeTransform
Returns a new instance of SanitizeTransform.
28 29 30 |
# File 'lib/tankobon/transform.rb', line 28 def initialize(padding=5) @padding = padding end |
Instance Method Details
#pad(num) ⇒ Object
32 33 34 |
# File 'lib/tankobon/transform.rb', line 32 def pad(num) "%0#{@padding}d-" % num end |
#transform(input) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tankobon/transform.rb', line 36 def transform(input) if not input =~ /[0-9]+/ then "#{pad(0)}#{input}" else input.gsub(/([0-9]+)/){pad($1.to_i)} .gsub(/([^0-9\-]+)/){""} .gsub(/(\-+)/){"-"} .gsub(/(\-$)/){""} .gsub(/(^\-)/){""} end end |