Sha256: 8bb89ab55a6edd3bd8668bbcc805587349aa467faad660f5942643212c4328b0

Contents?: true

Size: 938 Bytes

Versions: 3

Compression:

Stored size: 938 Bytes

Contents

module MixpanelMagicLamp

  class Formatter

    DEFAULT = 'values'

    def initialize(request)
      @response = request.response.handled_response.dup
    end

    def convert(format: DEFAULT)
      send :"to_#{format}"  
    end

    def to_values
      @response['data']['values']
    end

    def to_line
      @response['data']
    end

    def to_pie
      @response['data']['series'] = [ @response['data']['series'].first,
                                      @response['data']['series'].last ]
      date_for_value = @response['data']['series'].first

      @response['data']['values'].each do |section, values|
        @response['data']['values'][section] = @response['data']['values'][section][date_for_value]
      end

      @response['data']
    end

    def method_missing(method, *args)
      puts "Format '#{method}' not available. Formatting as 'to_#{DEFAULT}' instead."
      send :"to_#{DEFAULT}"
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mixpanel_magic_lamp-1.0.3 lib/mixpanel_magic_lamp/formatter.rb
mixpanel_magic_lamp-1.0.1 lib/mixpanel_magic_lamp/formatter.rb
mixpanel_magic_lamp-1.0.0 lib/mixpanel_magic_lamp/formatter.rb