Class: ProfileLinkGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/link_to_profile/profile_link_generator.rb

Defined Under Namespace

Classes: ArgumentError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProfileLinkGenerator

Returns a new instance of ProfileLinkGenerator.

Raises:



6
7
8
9
10
11
12
# File 'lib/link_to_profile/profile_link_generator.rb', line 6

def initialize(options = {})
  @options = options
  @username = options[:username]
  @network  = options[:network]

  raise ArgumentError if @username.nil? or @network.nil?
end

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



4
5
6
# File 'lib/link_to_profile/profile_link_generator.rb', line 4

def network
  @network
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/link_to_profile/profile_link_generator.rb', line 4

def options
  @options
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/link_to_profile/profile_link_generator.rb', line 4

def username
  @username
end

Instance Method Details



18
19
20
# File 'lib/link_to_profile/profile_link_generator.rb', line 18

def link
  "<a href='#{url}'>#{network}</a>"
end

#urlObject



14
15
16
# File 'lib/link_to_profile/profile_link_generator.rb', line 14

def url
  templates[network.to_s].sub(/{{username}}/, username)
end