Created
August 4, 2015 15:55
-
-
Save SnacksOnAPlane/c153551de93d1203380b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CompaniesHelper | |
ALL_SUFFIXES = %w(organic paid local) | |
ALL_ENGINES = %w(google yahoo bing search) | |
def hour_options_for_select | |
@hour_options ||= (0..23).map do |n| | |
suffix = n >= 12 ? 'PM' : 'AM' | |
hour = n % 12 | |
hour = 12 if hour.zero? | |
["#{hour} #{suffix}", n] | |
end | |
end | |
def wordpress_key(company) | |
"#{company.masked_id}x#{company.access_key}" | |
end | |
def suffixify(stems, suffixes) | |
[].tap do |retme| | |
stems.each do |stem| | |
suffixes.each do |suffix| | |
retme << "#{stem}_#{suffix}" | |
end | |
end | |
end | |
end | |
def referrer_keys(tracking_source) | |
engine, *types = tracking_source.split("_") | |
if ALL_ENGINES.include? engine | |
engines = (engine == "search") ? %w{google yahoo bing} : [engine] | |
suffixes = (types == %w(all)) ? ALL_SUFFIXES : types | |
return suffixify(engines, suffixes) | |
end | |
tracking_source = tracking_source.downcase | |
tracking_source = tracking_source[7, tracking_source.length - 7] if tracking_source[0,7] == 'http://' | |
tracking_source = tracking_source[4, tracking_source.length - 4] if tracking_source[0,4] == 'www.' | |
return [tracking_source] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment