Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/miga/common/format.rb

Overview

MiGA extensions to the String class.

Instance Method Summary collapse

Instance Method Details

#miga_nameObject

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.



119
120
121
# File 'lib/miga/common/format.rb', line 119

def miga_name
  gsub(/[^A-Za-z0-9_]/, '_')
end

#miga_name?Boolean

Is the string a MiGA-compliant name?

Returns:

  • (Boolean)


125
126
127
# File 'lib/miga/common/format.rb', line 125

def miga_name?
  !(self !~ /^[A-Za-z0-9_]+$/)
end

#miga_variables(vars) ⇒ Object

Replace {variables} using the vars hash



143
144
145
146
147
# File 'lib/miga/common/format.rb', line 143

def miga_variables(vars)
  o = "#{self}"
  vars.each { |k, v| o.gsub!("{{#{k}}}", v.to_s) }
  o
end

#unmiga_nameObject

Replace underscores by spaces or dots (depending on context).



131
132
133
# File 'lib/miga/common/format.rb', line 131

def unmiga_name
  gsub(/_(str|sp|subsp|pv)__/, '_\\1._').tr('_', ' ')
end

#wrap_width(width) ⇒ Object

Wraps the string with fixed Integer width.



137
138
139
# File 'lib/miga/common/format.rb', line 137

def wrap_width(width)
  gsub(/([^\n\r]{1,#{width}})/, "\\1\n")
end