Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/miga/common/format.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?.
-
#miga_variables(vars) ⇒ Object
Replace {variables} using the
vars
hash. -
#unmiga_name ⇒ Object
Replace underscores by spaces or other symbols 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.
140 141 142 |
# File 'lib/miga/common/format.rb', line 140 def miga_name gsub(/[^A-Za-z0-9_]/, '_') end |
#miga_name? ⇒ Boolean
Is the string a MiGA-compliant name?
146 147 148 |
# File 'lib/miga/common/format.rb', line 146 def miga_name? !(self !~ /^[A-Za-z0-9_]+$/) end |
#miga_variables(vars) ⇒ Object
Replace {variables} using the vars
hash
169 170 171 172 173 |
# File 'lib/miga/common/format.rb', line 169 def miga_variables(vars) o = self.dup vars.each { |k, v| o.gsub!("{{#{k}}}", v.to_s) } o end |
#unmiga_name ⇒ Object
Replace underscores by spaces or other symbols depending on context
152 153 154 155 156 157 158 159 |
# File 'lib/miga/common/format.rb', line 152 def unmiga_name gsub(/_(str|sp|subsp|pv)__/, '_\\1._') .gsub(/g_c_(content)/, 'G+C \\1') .gsub(/g_c_(skew)/, 'G-C \\1') .gsub(/a_t_(skew)/, 'A-T \\1') .gsub(/x_content/, &:capitalize) .tr('_', ' ') end |
#wrap_width(width) ⇒ Object
Wraps the string with fixed Integer width
.
163 164 165 |
# File 'lib/miga/common/format.rb', line 163 def wrap_width(width) gsub(/([^\n\r]{1,#{width}})/, "\\1\n") end |