Class: Exalted::StatSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/exalted/stat_set.rb

Overview

A StatSet holds a group of related Stats, such as those comprising an caste or aspect ability grouping. The Set has a name, and a record of the Stats within it.

# create a new stat set
@stat_set = StatSet.new('fire', %w{athletics dodge melee presence socialize})

# access the dodge stat
@stat_set['dodge']
# => #<Stat:dodge:0:false:>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, stats) ⇒ StatSet

Returns a new instance of StatSet.



28
29
30
31
32
33
34
# File 'lib/exalted/stat_set.rb', line 28

def initialize(name, stats)
  @name = name.to_sym
  @stat_names = stats
  @caste = false

  create_stats
end

Instance Attribute Details

#casteObject

is this a set of caste abilities?



26
27
28
# File 'lib/exalted/stat_set.rb', line 26

def caste
  @caste
end

#nameObject (readonly)

name of the stat set, typically the caste or aspect.



17
18
19
# File 'lib/exalted/stat_set.rb', line 17

def name
  @name
end

#stat_namesObject (readonly)

names of the stats in the set



20
21
22
# File 'lib/exalted/stat_set.rb', line 20

def stat_names
  @stat_names
end

#statsObject (readonly)

the stats themselves



23
24
25
# File 'lib/exalted/stat_set.rb', line 23

def stats
  @stats
end

Instance Method Details

#==(o) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/exalted/stat_set.rb', line 86

def ==(o)
  case o
  when String
    return self.name.to_s == o
  when Symbol
    return self.name == o
  when StatSet
    return (self == o.name) && (self.stat_names == o.stat_names)
  else
    return false
  end
end

#[](stat_name) ⇒ Object

hash style access to a Stat, based on the Stat’s name.



41
42
43
# File 'lib/exalted/stat_set.rb', line 41

def [](stat_name)
  self.detect { |stat| stat == stat_name }
end

#caste?Boolean

boolean accessor for if this is a caste stat set or no.

Returns:

  • (Boolean)


70
71
72
# File 'lib/exalted/stat_set.rb', line 70

def caste?
  (self.caste) ? true : false
end

#eachObject

yields each stat which has a non-zero rating in turn



46
47
48
49
50
# File 'lib/exalted/stat_set.rb', line 46

def each
  @stats.each do |stat|
    yield stat
  end
end

#each_ratedObject

yields only stats with a non-zero rating



53
54
55
56
57
# File 'lib/exalted/stat_set.rb', line 53

def each_rated
  self.each do |stat|
    yield stat if stat.rating > 0
  end
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
# File 'lib/exalted/stat_set.rb', line 99

def eql?(o)
  return false unless o.is_a?(StatSet)
  return false unless self.name.eql?(o.name)
  return false unless self.stat_names.eql?(o.stat_names)
  # detect for stats sharing the same name being not equal.
  stats_not_eql = self.stat_names.detect { |n| !(self[n].eql?(o[n])) }
  # if we have a stat that is not equal, we can return false
  # otherwise, it appears we must return true!
  return (stats_not_eql) ? false : true
end

#inspectObject



36
37
38
# File 'lib/exalted/stat_set.rb', line 36

def inspect
  "#<StatSet:#{name}:#{caste}:[#{stats.map {|s| s.inspect }.join(', ')}]>"
end

#size(all = true) ⇒ Object

returns the number of stats in the set.

If called as #size(false), only returns the number of stats with a non-zero rating



78
79
80
81
82
83
84
# File 'lib/exalted/stat_set.rb', line 78

def size(all=true)
  if all
    @stats.size
  else
    @stats.find_all {|s| s.rating > 0 }.size
  end
end