Module: Iroki::CoreExt::String
- Defined in:
- lib/iroki/core_ext/string/string.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #clean_name ⇒ Object
- #clean_strict ⇒ Object
- #has_color? ⇒ Boolean (also: #already_checked?)
- #has_single_quote? ⇒ Boolean
- #hex? ⇒ Boolean
- #single_quote ⇒ Object
Instance Method Details
#clean ⇒ Object
14 15 16 |
# File 'lib/iroki/core_ext/string/string.rb', line 14 def clean self.gsub(/'/, '"') end |
#clean_name ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/iroki/core_ext/string/string.rb', line 26 def clean_name if (match = self.has_color?) name = match[1] color = match[2] name.single_quote + color else self.single_quote end end |
#clean_strict ⇒ Object
37 38 39 |
# File 'lib/iroki/core_ext/string/string.rb', line 37 def clean_strict self.strip.gsub(/[^\p{Alnum}_]+/, "_").gsub(/_+/, "_") end |
#has_color? ⇒ Boolean Also known as: already_checked?
5 6 7 |
# File 'lib/iroki/core_ext/string/string.rb', line 5 def has_color? self.match(/(.*)(\[&!color="#[0-9A-Fa-f]{6}"\])/) end |
#has_single_quote? ⇒ Boolean
41 42 43 |
# File 'lib/iroki/core_ext/string/string.rb', line 41 def has_single_quote? self.match(/'/) end |
#hex? ⇒ Boolean
10 11 12 |
# File 'lib/iroki/core_ext/string/string.rb', line 10 def hex? self.match(/^#[0-9A-Fa-f]{6}$/) end |
#single_quote ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/iroki/core_ext/string/string.rb', line 18 def single_quote if self.match /\A'.*'\Z/ self.dup else %Q['#{self.clean}'] end end |