Class: PlaylyfeClient::V2::Metric

Inherits:
Metric
  • Object
show all
Defined in:
lib/playlyfe_client/v2/metric.rb

Direct Known Subclasses

CompoundMetric, PointMetric, SetMetric, StateMetric

Instance Attribute Summary collapse

Attributes inherited from Metric

#game

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/playlyfe_client/v2/metric.rb', line 7

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/playlyfe_client/v2/metric.rb', line 7

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/playlyfe_client/v2/metric.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/playlyfe_client/v2/metric.rb', line 7

def type
  @type
end

Class Method Details

.create_from(metric_hash, game) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/playlyfe_client/v2/metric.rb', line 9

def self.create_from(metric_hash,game)  
  require_relative "./metric/compound_metric.rb" 
  require_relative "./metric/point_metric.rb" 
  require_relative "./metric/set_metric.rb" 
  require_relative "./metric/state_metric.rb" 
  
  type=metric_hash[:type] || metric_hash["type"]
  case type
  when "set"
    PlaylyfeClient::V2::SetMetric.new(metric_hash,game)
  when "state"
    PlaylyfeClient::V2::StateMetric.new(metric_hash,game)
  when "point"
    PlaylyfeClient::V2::PointMetric.new(metric_hash,game)
  when "compound"
    PlaylyfeClient::V2::CompoundMetric.new(metric_hash,game)
  else
    fail PlaylyfeClient::MetricError.new("{\"error\": \"Unrecognized type\", \"error_description\": \"Class for metric type: '#{type}' from #{metric_hash} is unrecognized!\"}")
  end        

end

Instance Method Details

#apply_reward(reward, scores) ⇒ Object



31
32
33
# File 'lib/playlyfe_client/v2/metric.rb', line 31

def apply_reward(reward, scores)
  fail PlaylyfeClient::MetricError.new("{\"error\": \"Rewards can not be applyed!\", \"error_description\": \"For these metric, direct action rewards cannot be applied. Probably some rules based awards are used.\"}")
end