Class: Avatar::Source::SourceChain
- Inherits:
-
Object
- Object
- Avatar::Source::SourceChain
- Includes:
- AbstractSource
- Defined in:
- lib/avatar/source/source_chain.rb
Instance Method Summary collapse
-
#<<(source) ⇒ Object
Alias for
add_source
. -
#[](n) ⇒ Object
Retrieve the
n
<sup>th</sup> Source. -
#add_source(source) ⇒ Object
Add a source to the chain.
-
#avatar_url_for(person, options = {}) ⇒ Object
Iterate through the chain and return the first URL returned.
-
#clear! ⇒ Object
Clear the chain.
-
#empty? ⇒ Boolean
True unless a Source has been added.
-
#initialize ⇒ SourceChain
constructor
:nodoc:.
Constructor Details
#initialize ⇒ SourceChain
:nodoc:
9 10 11 |
# File 'lib/avatar/source/source_chain.rb', line 9 def initialize clear! end |
Instance Method Details
#<<(source) ⇒ Object
Alias for add_source
30 31 32 |
# File 'lib/avatar/source/source_chain.rb', line 30 def <<(source) add_source(source) end |
#[](n) ⇒ Object
Retrieve the n
<sup>th</sup> Source.
19 20 21 |
# File 'lib/avatar/source/source_chain.rb', line 19 def [](n) @chain[n] end |
#add_source(source) ⇒ Object
Add a source to the chain. source
must be an instance of (a subclass of) Avatar::Source::AbstractSource.
24 25 26 27 |
# File 'lib/avatar/source/source_chain.rb', line 24 def add_source(source) raise ArgumentError.new("#{source} is not an Avatar::Source::AbstractSource") unless source.kind_of?(Avatar::Source::AbstractSource) @chain << source end |
#avatar_url_for(person, options = {}) ⇒ Object
Iterate through the chain and return the first URL returned. Any error raised will propagate. Duplicates options
before passing so each Source receives the same arguments.
42 43 44 45 46 47 48 |
# File 'lib/avatar/source/source_chain.rb', line 42 def avatar_url_for(person, = {}) @chain.each do |source| result = source.avatar_url_for(person, .dup) return result unless result.nil? end return nil end |
#clear! ⇒ Object
Clear the chain
14 15 16 |
# File 'lib/avatar/source/source_chain.rb', line 14 def clear! @chain = [] end |
#empty? ⇒ Boolean
True unless a Source has been added.
35 36 37 |
# File 'lib/avatar/source/source_chain.rb', line 35 def empty? @chain.empty? end |