Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/miga/common.rb
Overview
MiGA extensions to the String class.
Instance Method Summary collapse
-
#miga_name ⇒ Object
Replace any character not allowed in a MiGA name for underscore (_).
-
#miga_name? ⇒ Boolean
Is the string a MiGA-compliant name?.
-
#unmiga_name ⇒ Object
Replace underscores by spaces or dots (depending on context).
-
#wrap_width(width) ⇒ Object
Wraps the string with fixed Integer
width
.
Instance Method Details
#miga_name ⇒ Object
Replace any character not allowed in a MiGA name for underscore (_). This results in a MiGA-compliant name EXCEPT for empty strings, that results in empty strings.
224 225 226 |
# File 'lib/miga/common.rb', line 224 def miga_name gsub(/[^A-Za-z0-9_]/, '_') end |
#miga_name? ⇒ Boolean
Is the string a MiGA-compliant name?
230 231 232 |
# File 'lib/miga/common.rb', line 230 def miga_name? !(self !~ /^[A-Za-z0-9_]+$/) end |
#unmiga_name ⇒ Object
Replace underscores by spaces or dots (depending on context).
236 237 238 |
# File 'lib/miga/common.rb', line 236 def unmiga_name gsub(/_(str|sp|subsp|pv)__/,"_\\1._").tr('_', ' ') end |
#wrap_width(width) ⇒ Object
Wraps the string with fixed Integer width
.
242 243 244 |
# File 'lib/miga/common.rb', line 242 def wrap_width(width) gsub(/([^\n\r]{1,#{width}})/,"\\1\n") end |