Class: Tumblr::Data::Photo

Inherits:
Post
  • Object
show all
Defined in:
lib/tumblr.rb

Instance Attribute Summary collapse

Attributes inherited from Post

#bookmarklet, #date, #postid, #url

Instance Method Summary collapse

Constructor Details

#initialize(elt, tz) ⇒ Photo

Returns a new instance of Photo.



166
167
168
169
170
171
172
173
174
175
# File 'lib/tumblr.rb', line 166

def initialize(elt, tz)
  super
  if elt.elements["photo-caption"]
    @caption = elt.elements["photo-caption"].text
  end
  @urls = Hash.new
  elt.elements.each("photo-url") do |url|
    @urls[url.attributes["max-width"].to_i] = url.text
  end
end

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



164
165
166
# File 'lib/tumblr.rb', line 164

def caption
  @caption
end

#urlsObject

Returns the value of attribute urls.



164
165
166
# File 'lib/tumblr.rb', line 164

def urls
  @urls
end

Instance Method Details

#to_xmlObject



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/tumblr.rb', line 177

def to_xml
  elt = super
  elt.attributes["type"] = "photo"
  if @caption
    (elt.add_element "photo-caption").text = @caption
  end
  @urls.each do |width, url|
    e = elt.add_element "photo-url", {"max-width" => width}
    e.text = url
  end
  return elt
end