Sha256: 207722155c77bfcc0e56784f6de4c9c262a922508ff0eda06257422ef1610913

Contents?: true

Size: 1.28 KB

Versions: 31

Compression:

Stored size: 1.28 KB

Contents

class Facebooker::Attachment
  
  def initialize
    @storage = {}
  end
  
  def self.hash_populating_accessor(*names)
    names.each do |name|
      define_method(name) do
        @storage[name]
      end
      define_method("#{name}=") do |val|
        @storage[name]=val
      end
    end
  end
  
  hash_populating_accessor :name,:href, :comments_xid, :description, :caption
  
  def add_media(hash)
    @storage[:media]||=[]
    @storage[:media] << hash
  end
  
  def add_image(source,href)
    add_media({:type=>"image",:src=>source,:href=>href})
  end
  
  def add_mp3(source,title=nil,artist=nil,album=nil)
    params = {:src=>source,:type=>"mp3"}
    params[:title] =  title unless title.nil?
    params[:artist] =  artist unless artist.nil?
    params[:album] =  album unless album.nil?
    add_media(params)
  end
  
  def add_flash(swfsource, imgsource, width=nil, height=nil, expanded_width=nil, expanded_height=nil)
    params={:type=>"flash",:swfsrc=>swfsource,:imgsrc=>imgsource}
    params[:width] = width unless width.nil?
    params[:height] = height unless height.nil?
    params[:expanded_width] = expanded_width unless expanded_width.nil?
    params[:expanded_height] = expanded_height unless expanded_height.nil?
    add_media(params)
  end
  
  def to_hash
    @storage
  end
  
  
end

Version data entries

31 entries across 31 versions & 9 rubygems

Version Path
facebooker-1.0.74 lib/facebooker/attachment.rb
facebooker-1.0.73 lib/facebooker/attachment.rb
facebooker-1.0.72 lib/facebooker/attachment.rb
facebooker-1.0.71 lib/facebooker/attachment.rb
facebooker-1.0.70 lib/facebooker/attachment.rb
benhutton-facebooker-1.0.69.2 lib/facebooker/attachment.rb
benhutton-facebooker-1.0.69.1 lib/facebooker/attachment.rb
facebooker-rails3-1.0.64 lib/facebooker/attachment.rb
facebooker-1.0.69 lib/facebooker/attachment.rb
cbaclig-facebooker-1.0.67.3 lib/facebooker/attachment.rb
facebooker-1.0.68 lib/facebooker/attachment.rb
cbaclig-facebooker-1.0.67.2 lib/facebooker/attachment.rb
facebooker-lite-1.0.67.2 lib/facebooker/attachment.rb
facebooker-lite-1.0.67.1 lib/facebooker/attachment.rb
facebooker-lite-1.0.67 lib/facebooker/attachment.rb
fotonauts-facebooker-1.0.67 lib/facebooker/attachment.rb
facebooker-1.0.67 lib/facebooker/attachment.rb
facebooker-1.0.66 lib/facebooker/attachment.rb
jet-facebooker-1.0.64 lib/facebooker/attachment.rb
facebooker-1.0.65 lib/facebooker/attachment.rb