Class: Exalted::StatSet
- Inherits:
-
Object
- Object
- Exalted::StatSet
- 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
-
#caste ⇒ Object
is this a set of caste abilities?.
-
#name ⇒ Object
readonly
name of the stat set, typically the caste or aspect.
-
#stat_names ⇒ Object
readonly
names of the stats in the set.
-
#stats ⇒ Object
readonly
the stats themselves.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#[](stat_name) ⇒ Object
hash style access to a Stat, based on the Stat’s name.
-
#caste? ⇒ Boolean
boolean accessor for if this is a caste stat set or no.
-
#each ⇒ Object
yields each stat which has a non-zero rating in turn.
-
#each_rated ⇒ Object
yields only stats with a non-zero rating.
- #eql?(o) ⇒ Boolean
-
#initialize(name, stats) ⇒ StatSet
constructor
A new instance of StatSet.
- #inspect ⇒ Object
-
#size(all = true) ⇒ Object
returns the number of stats in the set.
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
#caste ⇒ Object
is this a set of caste abilities?
26 27 28 |
# File 'lib/exalted/stat_set.rb', line 26 def caste @caste end |
#name ⇒ Object (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_names ⇒ Object (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 |
#stats ⇒ Object (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.
70 71 72 |
# File 'lib/exalted/stat_set.rb', line 70 def caste? (self.caste) ? true : false end |
#each ⇒ Object
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_rated ⇒ Object
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. > 0 end end |
#eql?(o) ⇒ 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 |
#inspect ⇒ Object
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. > 0 }.size end end |