Module: IrokiLib::CoreExt::String
- Included in:
- Utils
- Defined in:
- lib/iroki_lib/core_ext/string/string.rb
Instance Method Summary collapse
- #clean(str) ⇒ Object
- #clean_name(name) ⇒ Object
- #has_color?(name) ⇒ Boolean (also: #already_checked?)
- #hex?(str) ⇒ Boolean
Instance Method Details
#clean(str) ⇒ Object
9 10 11 |
# File 'lib/iroki_lib/core_ext/string/string.rb', line 9 def clean str str.gsub(/[^\p{Alnum}_]+/, "_").gsub(/_+/, "_") end |
#clean_name(name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/iroki_lib/core_ext/string/string.rb', line 18 def clean_name name if name.nil? nil else if (match = has_color? name) name = match[1] color = match[2] clean(name) + color else clean(name) end end end |
#has_color?(name) ⇒ Boolean Also known as: already_checked?
13 14 15 |
# File 'lib/iroki_lib/core_ext/string/string.rb', line 13 def has_color? name name.match(/(.*)(\[&!color="#[0-9A-Fa-f]{6}"\])/) end |
#hex?(str) ⇒ Boolean
5 6 7 |
# File 'lib/iroki_lib/core_ext/string/string.rb', line 5 def hex? str str.match(/^#[0-9A-Fa-f]{6}$/) end |