Class: Viddler::SitemapFile
- Inherits:
-
Object
- Object
- Viddler::SitemapFile
- Defined in:
- lib/viddler/sitemap_file.rb
Instance Attribute Summary collapse
-
#videos ⇒ Object
readonly
An array of video hash object that will be included in the SitemapFile.
Instance Method Summary collapse
-
#add_video(video) ⇒ Object
Add a video to this sitemap file.
-
#initialize ⇒ SitemapFile
constructor
A new instance of SitemapFile.
-
#to_xml ⇒ String
The XML string for this SitemapFile.
-
#write!(folder, file_number) ⇒ Object
Write the xml content for this SitemapFile to disk.
Constructor Details
#initialize ⇒ SitemapFile
Returns a new instance of SitemapFile.
6 7 8 |
# File 'lib/viddler/sitemap_file.rb', line 6 def initialize @videos = [] end |
Instance Attribute Details
#videos ⇒ Object (readonly)
An array of video hash object that will be included in the SitemapFile
4 5 6 |
# File 'lib/viddler/sitemap_file.rb', line 4 def videos @videos end |
Instance Method Details
#add_video(video) ⇒ Object
Add a video to this sitemap file
12 13 14 15 |
# File 'lib/viddler/sitemap_file.rb', line 12 def add_video(video) @videos << video return true end |
#to_xml ⇒ String
The XML string for this SitemapFile
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/viddler/sitemap_file.rb', line 19 def to_xml @builder = Builder::XmlMarkup.new(:indent => 2) @builder.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8') @builder.urlset('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9', 'xmlns:video' => 'http://www.google.com/schemas/sitemap-video/1.1') do | xml| @videos.each do |video| downloadable = video['permissions'] && video['permissions']['download'] != 'private' = video['permissions'] && video['permissions']['embed'] != 'private' xml.url do |xml| xml.loc(video['permalink']) xml.tag!('video:video') do xml.tag!('video:thumbnail_loc', "http://www.viddler.com/thumbnail/#{video['id']}") xml.tag!('video:title', video['title']) xml.tag!('video:description', video['description']) if downloadable xml.tag!('video:content_loc', video['files'].first['url']) end xml.tag!('video:player_loc', "http://www.viddler.com/embed/#{video['id']}", :allow_embed => ? 'yes' : 'no') xml.tag!('video:duration', video['length']) xml.tag!('video:view_count', video['view_count']) xml.tag!('video:publication_date', Time.at(video['upload_time'].to_i).strftime('%Y-%m-%d')) xml.tag!('video:family_friendly', 'yes') xml.tag!('video:live', 'no') end end end end return @builder.target! end |
#write!(folder, file_number) ⇒ Object
Write the xml content for this SitemapFile to disk
54 55 56 57 |
# File 'lib/viddler/sitemap_file.rb', line 54 def write!(folder, file_number) path = "#{folder}/sitemap-#{file_number}.xml" File.open(path, 'w') { |f| f.write(self.to_xml) } end |