Class: UtmGenerator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/utm_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/utm_generator.rb', line 3

def url
  @url
end

#utm_campaignObject

Returns the value of attribute utm_campaign.



3
4
5
# File 'lib/utm_generator.rb', line 3

def utm_campaign
  @utm_campaign
end

#utm_contentObject

Returns the value of attribute utm_content.



3
4
5
# File 'lib/utm_generator.rb', line 3

def utm_content
  @utm_content
end

#utm_mediumObject

Returns the value of attribute utm_medium.



3
4
5
# File 'lib/utm_generator.rb', line 3

def utm_medium
  @utm_medium
end

#utm_sourceObject

Returns the value of attribute utm_source.



3
4
5
# File 'lib/utm_generator.rb', line 3

def utm_source
  @utm_source
end

#utm_termObject

Returns the value of attribute utm_term.



3
4
5
# File 'lib/utm_generator.rb', line 3

def utm_term
  @utm_term
end

Instance Method Details

#generate_urlObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/utm_generator.rb', line 8

def generate_url
  if valid?
    uri = URI(url)
    params = []
    params << [:utm_source, utm_source]
    params << [:utm_medium, utm_medium] unless utm_medium.blank?
    params << [:utm_campaign, utm_campaign] unless utm_campaign.blank?
    params << [:utm_term, utm_term] unless utm_term.blank?
    params << [:utm_content, utm_content] unless utm_content.blank?
    uri.query = URI.encode_www_form(params)
    uri.to_s
  end
end