Module: Awesome::Definitions::Bits::ClassMethods
- Defined in:
- lib/awesome/definitions/bits.rb
Instance Method Summary collapse
- #array_to_middle_regex(arr, whitespace = false) ⇒ Object
- #get_class(name) ⇒ Object
- #make_symring(var) ⇒ Object
- #modifier_regex(middle) ⇒ Object
- #modifier_regex_from_array(arr, whitespace = false) ⇒ Object
-
#symring_equalizer(one, two) ⇒ Object
In dealing with symbols and strings and params from requests comparisons can fail even when we want them to pass.
- #unmake_symring(var) ⇒ Object
Instance Method Details
#array_to_middle_regex(arr, whitespace = false) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/awesome/definitions/bits.rb', line 19 def array_to_middle_regex(arr, whitespace = false) return '' if arr.empty? arr = whitespace ? arr.map {|x| '(\s*' + x + '\s*)'} : arr.map {|x| '(' + x + ')'} arr.join('|') end |
#get_class(name) ⇒ Object
11 12 13 |
# File 'lib/awesome/definitions/bits.rb', line 11 def get_class(name) const_get(name) unless name.blank? end |
#make_symring(var) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/awesome/definitions/bits.rb', line 39 def make_symring(var) if var.is_a?(Symbol) return ":#{var}" elsif var.is_a?(String) var.include?(':') ? var.strip : ":#{var.strip}" end end |
#modifier_regex(middle) ⇒ Object
27 28 29 |
# File 'lib/awesome/definitions/bits.rb', line 27 def modifier_regex(middle) Regexp.new(middle) end |
#modifier_regex_from_array(arr, whitespace = false) ⇒ Object
15 16 17 |
# File 'lib/awesome/definitions/bits.rb', line 15 def modifier_regex_from_array(arr, whitespace = false) self.modifier_regex(self.array_to_middle_regex(arr, whitespace)) end |
#symring_equalizer(one, two) ⇒ Object
In dealing with symbols and strings and params from requests
comparisons can fail even when we want them to pass.
This prevents those unwanted failures We will compare strings of this format “:ebay”
35 36 37 |
# File 'lib/awesome/definitions/bits.rb', line 35 def symring_equalizer(one, two) return self.make_symring(one) == self.make_symring(two) end |
#unmake_symring(var) ⇒ Object
47 48 49 |
# File 'lib/awesome/definitions/bits.rb', line 47 def unmake_symring(var) return "#{var}".delete(':') end |