lib/redismetrics/client.rb
# Applys the conversion method +convert+ by mapping the enum +enum+ in
# various ways and returning another enum.
Applys the conversion method +convert+ by mapping the enum +enum+ in
various ways and returning another enum.
Applys the conversion method + convert + by mapping the enum + enum + in various ways and returning another enum .
def apply_conversion(convert, enum)
    case convert
    when Symbol
      enum.map { |t, v| [ Time.at(t / MS), v.send(convert) ] }
    when Proc
      case convert.arity
      when 1
        enum.map { |t, v| [ Time.at(t / MS), convert.(v) ] }
      when 2
        enum.map { |t, v| convert.(Time.at(t / MS), v) }
      else
        raise ArgumentError, 'convert arity has to be 1 or 2'
      end
    when nil
      enum.map { |t, v| [ Time.at(t / MS), v ] }
    else
      if c = convert.ask_and_send(:to_proc) and (1..2).include?(c.arity)
        apply_conversion(c, enum)
      else
        raise ArgumentError, 'convert has to be either symbol or proc'
      end
    end
  end
def apply_conversion ( convert , enum ) case convert when Symbol enum . map { | t , v | [ Time . at ( t / MS ) , v . send ( convert ) ] } when Proc case convert . arity when 1 enum . map { | t , v | [ Time . at ( t / MS ) , convert . ( v ) ] } when 2 enum . map { | t , v | convert . ( Time . at ( t / MS ) , v ) } else raise ArgumentError , 'convert arity has to be 1 or 2' end when nil enum . map { | t , v | [ Time . at ( t / MS ) , v ] } else if c = convert . ask_and_send ( :to_proc ) and ( 1 .. 2 ) . include? ( c . arity ) apply_conversion ( c , enum ) else raise ArgumentError , 'convert has to be either symbol or proc' end end end
Applys the conversion method +convert+ by mapping the enum +enum+ in
various ways and returning another enum.
Applys the conversion method + convert + by mapping the enum + enum + in various ways and returning another enum .
convert
enum