class FeatureLocation

Public Instance Methods

title_with_dimensions() click to toggle source
# File lib/buweb/feature_location.rb, line 43
def title_with_dimensions
  preferred_image_width.present? ? "#{title} (#{preferred_image_width}x#{preferred_image_height})" : title
end
to_s() click to toggle source
# File lib/buweb/feature_location.rb, line 39
def to_s
  "#{site.title}: #{title}"
end

Protected Instance Methods

set_slug() click to toggle source
# File lib/buweb/feature_location.rb, line 55
def set_slug
  self.slug = title.parameterize if title?
end
uri?(string) click to toggle source
# File lib/buweb/feature_location.rb, line 67
def uri?(string)
  uri = URI.parse(string)
  %w( http https ).include?(uri.scheme)
rescue URI::BadURIError
  false
rescue URI::InvalidURIError
  false
end
url_formatting() click to toggle source
# File lib/buweb/feature_location.rb, line 59
def url_formatting
  if url.present?
    unless (uri?(url) || valid_relative_url?(url))
      errors.add :url, 'either needs to be a full url or a valid relative url.'
    end
  end
end
valid_relative_url?(string) click to toggle source
# File lib/buweb/feature_location.rb, line 76
def valid_relative_url?(string)
  string.starts_with?('/')
end

Private Instance Methods

preferred_image() click to toggle source
# File lib/buweb/feature_location.rb, line 48
def preferred_image
  if (preferred_image_height.blank? && !preferred_image_width.blank?) || (!preferred_image_height.blank? && preferred_image_width.blank?)
    errors.add :base, 'Both preferred image height and width need to be filled in.'
  end
end