Class: Aviary::ImageHost

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/aviary/image_host.rb

Direct Known Subclasses

Flickr, Plixi, Twitpic, Yfrog

Defined Under Namespace

Classes: Flickr, Plixi, Twitpic, Yfrog

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.availableObject

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

Returns:

  • (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

#hrefObject

Link to the original photo. Descendant classes must implement this method.

Raises exception until implemented.

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/aviary/image_host.rb', line 63

def href
  raise NotImplementedError
end

#srcObject

Link to the image. Descendant classes must implement this method.

Raises exception until implemented.

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/aviary/image_host.rb', line 70

def src
  raise NotImplementedError
end