Class: Avatar::Source::StaticUrlSource

Inherits:
Object
  • Object
show all
Includes:
AbstractSource
Defined in:
lib/avatar/source/static_url_source.rb

Overview

Source representing a constant URL. Good as a default or last-resort source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ StaticUrlSource

Create a new source with static url url.

Raises:

  • (ArgumentError)


13
14
15
16
# File 'lib/avatar/source/static_url_source.rb', line 13

def initialize(url)
  raise ArgumentError.new("URL cannot be nil") if url.nil?
  @url = url.to_s
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/avatar/source/static_url_source.rb', line 10

def url
  @url
end

Instance Method Details

#avatar_url_for(person, options = {}) ⇒ Object

Returns nil if person is nil; the static url otherwise.



19
20
21
# File 'lib/avatar/source/static_url_source.rb', line 19

def avatar_url_for(person, options = {})
  person.nil? ? nil : url
end