Module: SocialUrl

Includes:
ERB::Util
Defined in:
lib/social_url.rb,
lib/social_url/errors.rb,
lib/social_url/google.rb,
lib/social_url/message.rb,
lib/social_url/twitter.rb,
lib/social_url/version.rb,
lib/social_url/facebook.rb,
lib/social_url/pinterest.rb

Defined Under Namespace

Classes: Facebook, Google, Message, Pinterest, Twitter, UnsupportedNetworkError

Constant Summary collapse

NETWORKS =
[:facebook, :google, :pinterest, :twitter]
KEYS =
{
  u: :url,
  url: :u,
  description: :text,
  text: :description
}
VERSION =
'1.0.3'

Class Method Summary collapse

Class Method Details

.filtered_params(options, params) ⇒ Object



61
62
63
64
65
66
# File 'lib/social_url.rb', line 61

def filtered_params(options, params)
  params.collect do |param|
    next unless options[param]
    "#{param}=#{options[param]}"
  end.compact.join('&')
end

.networksObject



24
25
26
# File 'lib/social_url.rb', line 24

def networks
  NETWORKS
end

.normalize(options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/social_url.rb', line 28

def normalize(options)
  opts = {}

  options.each do |key, value|
    next unless value

    opts[key] = normalize_string(value) if value.is_a?(String)
    opts[key] = normalize_array(value) if value.is_a?(Array)
  end

  normalize_keys(opts)
end

.normalize_array(array) ⇒ Object



55
56
57
58
59
# File 'lib/social_url.rb', line 55

def normalize_array(array)
  array.collect do |value|
    ERB::Util.url_encode(value)
  end.join(',')
end

.normalize_keys(options) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/social_url.rb', line 41

def normalize_keys(options)
  opts = options.dup

  options.each do |key, value|
    opts[KEYS[key]] = opts[key] if KEYS[key]
  end

  opts
end

.normalize_string(string) ⇒ Object



51
52
53
# File 'lib/social_url.rb', line 51

def normalize_string(string)
  ERB::Util.url_encode(string)
end