Class: Stats::StatResult

Inherits:
Object show all
Defined in:
lib/stats/stat.rb

Overview

Encapsultates a statistic result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ StatResult

StatResult initializer

Options Hash (args):

  • :stat_id,'stat_id' (String)

    stat_id to assign to the result

  • :value,'value' (Object)

    value to assign to the result


76
77
78
79
80
81
82
# File 'lib/stats/stat.rb', line 76

def initialize(args = {})
  attr_from_args args,
                 :stat_id => nil,
                 :stat    => nil,
                 :args    =>  [],
                 :value   => nil
end

Instance Attribute Details

#argsObject

array of args used to generated the stat


67
68
69
# File 'lib/stats/stat.rb', line 67

def args
  @args
end

#statObject

handle to the stat this result belongs to


64
65
66
# File 'lib/stats/stat.rb', line 64

def stat
  @stat
end

#stat_idObject

id of the statistic this result belongs to


61
62
63
# File 'lib/stats/stat.rb', line 61

def stat_id
  @stat_id
end

#valueObject

actual value of the result


70
71
72
# File 'lib/stats/stat.rb', line 70

def value
  @value
end

Class Method Details

.json_create(o) ⇒ Object

Create new stat result from json representation


98
99
100
101
# File 'lib/stats/stat.rb', line 98

def self.json_create(o)
  res = new(o['data'])
  return res
end

Instance Method Details

#to_json(*a) ⇒ Object

Convert stat result to json representation and return it


89
90
91
92
93
94
95
# File 'lib/stats/stat.rb', line 89

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       =>
      {:stat_id => stat_id, :stat => stat, :args => args, :value => value}
  }.to_json(*a)
end

#to_sObject


84
85
86
# File 'lib/stats/stat.rb', line 84

def to_s
  "stat-result-#{stat_id} (#{value})"
end