Sha256: 5551a1b32199eab564d9dec80b7f8093410123e6eadb085acb7160ce18c2cedc

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

module Evvnt
  # Public: Returns report for a given {Evvnt::Event} from the API.
  #
  # Examples
  #
  #   Evvnt::Report.find(event_id: '...')
  #
  class Report < Evvnt::Base

    singular_resource!

    belongs_to :event

    ##
    # GET /events/:event_id/report View report data for my event
    define_action :show

    private

    def format_hash_attribute(key, value)
      case key
      when /^(referrers|search\_indexing)$/
        send(:"format_#{key}_attribute", key, value)
      else
        super
      end
    end

    def format_array_attribute(key, value)
      case key
      when /^(clicks\_by\_day|broadcasts)$/
        send(:"format_#{key}_attribute", key, value)
      else
        super
      end
    end

    def format_referrers_attribute(_key, value)
      value.to_a.map { |url, count| Evvnt::Referrer.new(url: url, count: count) }
    end

    def format_search_indexing_attribute(_key, value)
      value.to_a.map { |name, url| Evvnt::SearchIndexing.new(name: name, url: url) }
    end

    def format_broadcasts_attribute(_key, value)
      Array(value).map { |atts| Evvnt::Broadcast.new(atts) }
    end

    def format_clicks_by_day_attribute(_key, value)
      value.to_a[1..-1].map do |date, twitter, myspace, total|
        Evvnt::ClicksByDay.new(date: date, twitter: twitter,
                               myspace: myspace, total: total)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
evvnt-0.2.6 lib/evvnt/report.rb
evvnt-0.2.5 lib/evvnt/report.rb
evvnt-0.2.4 lib/evvnt/report.rb
evvnt-0.2.3 lib/evvnt/report.rb
evvnt-0.2.2 lib/evvnt/report.rb
evvnt-0.2.1 lib/evvnt/report.rb
evvnt-0.2.0 lib/evvnt/report.rb
evvnt-0.1.0 lib/evvnt/report.rb