Class: Aviary::ImageHost
- Inherits:
-
Object
- Object
- Aviary::ImageHost
- Includes:
- DataMapper::Resource
- Defined in:
- lib/aviary/image_host.rb
Defined Under Namespace
Classes: Flickr, Plixi, Twitpic, Yfrog
Class Method Summary collapse
-
.available ⇒ Object
Get descendants which are available for searching.
- .available? ⇒ Boolean
-
.match(text) ⇒ Object
Build an array of captures from matching text.
-
.match_and_create(status) ⇒ Object
Like match, but instead of returning an array of captures strings it creates new records with the captured token.
-
.matches(regex = nil) ⇒ Object
Set and get regular expressions for matching against links to image hosts.
Instance Method Summary collapse
-
#href ⇒ Object
Link to the original photo.
-
#src ⇒ Object
Link to the image.
Class Method Details
.available ⇒ Object
Get descendants which are available for searching. Descendant classes should implement this method if they require additional configuration before they are available. Eg: ImageHost::Flickr requires an API key to be set.
Returns array of descendants.
23 24 25 |
# File 'lib/aviary/image_host.rb', line 23 def self.available @available ||= descendants.select { |d| d.available? } end |
.available? ⇒ Boolean
27 28 29 |
# File 'lib/aviary/image_host.rb', line 27 def self.available? true end |
.match(text) ⇒ Object
Build an array of captures from matching text. Will capture multiple times. An empty array means there were no captures.
Returns array of captured strings.
45 46 47 |
# File 'lib/aviary/image_host.rb', line 45 def self.match(text) text.scan(Regexp.union(matches)).flatten.compact end |
.match_and_create(status) ⇒ Object
Like match, but instead of returning an array of captures strings it creates new records with the captured token. Status is an object which has a text attribute returned by Twitter.
Returns nothing.
54 55 56 57 58 |
# File 'lib/aviary/image_host.rb', line 54 def self.match_and_create(status) match(status.text).each do |capture| create(:token => capture, :status => status) end end |
.matches(regex = nil) ⇒ Object
Set and get regular expressions for matching against links to image hosts. Passing an argument appends the it to the array. Passing nothing gets the regular expressions.
Returns array of regular expressions.
36 37 38 39 |
# File 'lib/aviary/image_host.rb', line 36 def self.matches(regex = nil) @matches = (@matches || []) << regex if regex @matches end |
Instance Method Details
#href ⇒ Object
Link to the original photo. Descendant classes must implement this method.
Raises exception until implemented.
63 64 65 |
# File 'lib/aviary/image_host.rb', line 63 def href raise NotImplementedError end |
#src ⇒ Object
Link to the image. Descendant classes must implement this method.
Raises exception until implemented.
70 71 72 |
# File 'lib/aviary/image_host.rb', line 70 def src raise NotImplementedError end |