Class: Stats::PercentWatchedReport

Inherits:
Report
  • Object
show all
Defined in:
lib/stats/percent_watched_report.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Report

#==, #[], array_to_csv, array_to_xml, csv_labels, format_csv_value, #initialize, pad_reports, set_attributes, set_numeric_attributes, strip_label, #the_csv_keys, #to_csv

Constructor Details

This class inherits a constructor from Stats::Report

Class Method Details

.csv_keysObject



24
25
26
# File 'lib/stats/percent_watched_report.rb', line 24

def self.csv_keys
  [ :percent_watched, :percent_of_watches, :fall_off ]
end

.to_amcharts(reports, show_date, show_date_range, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stats/percent_watched_report.rb', line 28

def self.to_amcharts(reports, show_date, show_date_range, options = {})
  xml = Builder::XmlMarkup.new
  xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
  xml.chart do
    xml.series do    
      reports.each_with_index do |report, index|
        xml.value "#{report.percent_watched.to_i}%", :xid => report.percent_watched
      end
    end

    xml.graphs do
      xml.graph :gid => 'percent_watched' do
        reports.each_with_index do |report, index|
          xml.value sprintf('%.1f', report.percent_of_watches), :xid => report.percent_watched
        end
      end
    end
  end
end

Instance Method Details

#to_json(options = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/stats/percent_watched_report.rb', line 16

def to_json(options = {})
  report = HashWithIndifferentAccess.new
  report['percent_watched'] = percent_watched
  report['percent_of_watches'] = percent_of_watches
  report['fall_off'] = fall_off
  report.to_json
end

#to_xml(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/stats/percent_watched_report.rb', line 5

def to_xml options = {}
  xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
  xml.instruct! unless options[:skip_instruct]

  xml.__send__(@label) do
    xml.percent_watched @percent_watched
    xml.percent_of_watches @percent_of_watches
    xml.fall_off @fall_off
  end
end