Class: StreamStats::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/stream_stats/counter.rb,
ext/stream_stats/stream_stats_counter.c

Constant Summary collapse

ATTRIBUTE_LIST =
[:count, :sum, :min, :max, :mean, :stddev]

Instance Method Summary collapse

Constructor Details

#initializeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'ext/stream_stats/stream_stats_counter.c', line 8

static VALUE strstat_counter_init(VALUE self) {
  counter *i_counter;
  VALUE data;

  i_counter = (counter *) malloc(sizeof(counter));

  init_counter(i_counter);

  data = Data_Wrap_Struct(counter_class, NULL, free, i_counter);
  rb_ivar_set(self, rb_intern("internal_struct"), data);

  return Qnil;
}

Instance Method Details

#<<(rb_sample) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ext/stream_stats/stream_stats_counter.c', line 31

static VALUE strstat_counter_add_sample(VALUE self, VALUE rb_sample) {
  double sample;
  counter *i_counter;
  int returned;

  sample = NUM2DBL(rb_sample);

  i_counter = (counter*) strstat_get_struct(self);

  returned = counter_add_sample(i_counter, sample);
  if (returned != 0) {
    rb_raise(rb_eRuntimeError, "add sample returned %d", returned);
  }

  return Qnil;
}

#countObject



48
49
50
51
52
53
54
# File 'ext/stream_stats/stream_stats_counter.c', line 48

static VALUE strstat_counter_count(VALUE self) {
  counter *i_counter;

  i_counter = (counter*) strstat_get_struct(self);

  return LONG2NUM(counter_count(i_counter));
}

#inspectObject



6
7
8
9
10
11
# File 'lib/stream_stats/counter.rb', line 6

def inspect
  attr_list = ATTRIBUTE_LIST.map do |method|
    "#{method.to_s}: #{self.send(method)}"
  end * ', '
  "#{self.to_s} {#{attr_list}}"
end

#maxObject



66
67
68
# File 'ext/stream_stats/stream_stats_counter.c', line 66

static VALUE strstat_counter_max(VALUE self) {
  return strstat_counter_commoncall(self, counter_max);
}

#meanObject



69
70
71
# File 'ext/stream_stats/stream_stats_counter.c', line 69

static VALUE strstat_counter_mean(VALUE self) {
  return strstat_counter_commoncall(self, counter_mean);
}

#minObject



63
64
65
# File 'ext/stream_stats/stream_stats_counter.c', line 63

static VALUE strstat_counter_min(VALUE self) {
  return strstat_counter_commoncall(self, counter_min);
}

#squared_sumObject



78
79
80
# File 'ext/stream_stats/stream_stats_counter.c', line 78

static VALUE strstat_counter_squared_sum(VALUE self) {
  return strstat_counter_commoncall(self, counter_squared_sum);
}

#stddevObject



72
73
74
# File 'ext/stream_stats/stream_stats_counter.c', line 72

static VALUE strstat_counter_stddev(VALUE self) {
  return strstat_counter_commoncall(self, counter_stddev);
}

#sumObject



75
76
77
# File 'ext/stream_stats/stream_stats_counter.c', line 75

static VALUE strstat_counter_sum(VALUE self) {
  return strstat_counter_commoncall(self, counter_sum);
}