Module: Awesome::Definitions::Types::ClassMethods
- Defined in:
- lib/awesome/definitions/types.rb
Instance Method Summary collapse
- #get_search_type_from_modifier(mod) ⇒ Object
- #get_type_modifiers(anytext, type = nil, multiple_types_as_one = false) ⇒ Object
-
#match_types ⇒ Object
match a regex for the type.
- #search_type_keys(symring = true) ⇒ Object
- #search_type_modifiers(symring = true) ⇒ Object
- #search_type_modifiers_regex(whitespace = false, multiple_types_as_one = false) ⇒ Object
- #search_types_enabled ⇒ Object
- #type_modifiers_to_search_types ⇒ Object
-
#valid_type_modifiers(anytext, type, multiple_types_as_one = false) ⇒ Object
type param might be an array of types.
Instance Method Details
#get_search_type_from_modifier(mod) ⇒ Object
75 76 77 |
# File 'lib/awesome/definitions/types.rb', line 75 def get_search_type_from_modifier(mod) self.search_types[:search_types_to_type_modifiers][mod] end |
#get_type_modifiers(anytext, type = nil, multiple_types_as_one = false) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/awesome/definitions/types.rb', line 67 def get_type_modifiers(anytext, type = nil, multiple_types_as_one = false) mods = anytext.scan(self.search_type_modifiers_regex(false, multiple_types_as_one)).flatten.compact.reject {|x| x == ''} #If no type mods are in the search string then the type requested is valid so we pretend it was requested as a modifier mods = mods.empty? ? multiple_types_as_one ? type : [self.search_types[:search_types_to_type_modifiers][self.make_symring(type)]] : mods puts "get_type_modifiers: #{mods.inspect}" if self.verbose_types mods end |
#match_types ⇒ Object
match a regex for the type
29 30 31 32 33 |
# File 'lib/awesome/definitions/types.rb', line 29 def match_types return self.search_types[:search_type_regexes].map do |key,value| self.search_query.match(value) ? key : nil end.compact end |
#search_type_keys(symring = true) ⇒ Object
16 17 18 |
# File 'lib/awesome/definitions/types.rb', line 16 def search_type_keys(symring = true) self.search_types[:search_types_to_type_modifiers].map {|k,v| symring ? k : self.unmake_symring(k)} end |
#search_type_modifiers(symring = true) ⇒ Object
20 21 22 |
# File 'lib/awesome/definitions/types.rb', line 20 def search_type_modifiers(symring = true) self.search_types[:search_types_to_type_modifiers].map {|k,v| symring ? v : self.unmake_symring(v)} end |
#search_type_modifiers_regex(whitespace = false, multiple_types_as_one = false) ⇒ Object
79 80 81 82 |
# File 'lib/awesome/definitions/types.rb', line 79 def search_type_modifiers_regex(whitespace = false, multiple_types_as_one = false) #return self.modifier_regex_from_arrays(self.looped_array(self.search_type_modifiers), whitespace) self.modifier_regex_from_array(multiple_types_as_one ? self.search_type_keys : self.search_type_modifiers, whitespace) end |
#search_types_enabled ⇒ Object
12 13 14 |
# File 'lib/awesome/definitions/types.rb', line 12 def search_types_enabled self.search_type_keys(false) - [] end |
#type_modifiers_to_search_types ⇒ Object
24 25 26 |
# File 'lib/awesome/definitions/types.rb', line 24 def type_modifiers_to_search_types self.search_types[:search_types_to_type_modifiers].invert end |
#valid_type_modifiers(anytext, type, multiple_types_as_one = false) ⇒ Object
type param might be an array of types
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/awesome/definitions/types.rb', line 36 def valid_type_modifiers(anytext, type, multiple_types_as_one = false) puts "checking valid_type_modifiers: #{anytext}, type: #{type.inspect}, multiple_types_as_one: #{multiple_types_as_one}" if self.verbose_types # Weed out invalid type requests if multiple_types_as_one #when using multiple types as one the keys are the modifiers, and the values are the search types allowed = self.search_type_keys & type valid_mods = allowed.map do |mod| self.get_search_type_from_modifier(mod) end.flatten.compact else #when NOT using multiple types as one the keys are the types, and the values are the modifiers type = self.make_symring(type) return [] unless self.search_type_keys.include?(type) mods = self.get_type_modifiers(anytext, type) searchie = self.type_modifiers_to_search_types matchie = self.match_types valid_mods = mods.select do |mod| indy = matchie.index(searchie[mod]) puts "type mod #{mod.inspect} => #{searchie[mod].inspect} == #{indy ? matchie[indy].inspect : "nil"} == #{type.inspect}" if self.verbose_types !indy.nil? && !matchie.nil? && !searchie.nil? && self.symring_equalizer(searchie[mod], type) && self.symring_equalizer(matchie[indy], type) # (multiple_types_as_one ? type.include?(searchie[mod]) : self.symring_equalizer(searchie[mod], type)) && # (multiple_types_as_one ? type.include?(matchie[indy]) : self.symring_equalizer(matchie[indy], type)) end end puts "valid_type_modifiers: #{valid_mods.inspect}" if self.verbose_types return valid_mods end |