Module: OrbitalFields::UrlLookup
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/orbital_fields/url_lookup.rb
Defined Under Namespace
Modules: ClassMethods
Classes: UrlLookupFieldValidator
Instance Method Summary
collapse
Instance Method Details
#find_by_url_lookup(input) ⇒ Object
29
30
31
|
# File 'lib/orbital_fields/url_lookup.rb', line 29
def find_by_url_lookup(input)
self.class.find_by_url_lookup(input)
end
|
#make_url_safe(input) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/orbital_fields/url_lookup.rb', line 33
def make_url_safe(input)
return nil unless input.class == String
input = input.strip
input.downcase!
input = input.gsub(/'|"/, "")
input = input.gsub(/!|\?/, "_")
input = input.gsub(/[\W]{1,}/, "_")
input = input.gsub(/_{2,}/, "_")
input = input.dasherize
input = input.gsub(/^(-{1,})?([a-z0-9][a-z0-9\-]*[a-z0-9])(-{1,})?$/, '\2')
end
|
#to_param ⇒ Object
45
46
47
|
# File 'lib/orbital_fields/url_lookup.rb', line 45
def to_param
url_lookup
end
|
#url_lookup_callback ⇒ Object
53
54
55
56
57
|
# File 'lib/orbital_fields/url_lookup.rb', line 53
def url_lookup_callback
if new_record? || send("#{self.lookup_field.to_s}_changed?") || url_lookup.blank?
self.url_lookup = make_url_safe(send(self.lookup_field.to_s))
end
end
|
#url_lookup_field ⇒ Object
49
50
51
|
# File 'lib/orbital_fields/url_lookup.rb', line 49
def url_lookup_field
self.lookup_field
end
|