Class: Characterizable::Characteristic
- Inherits:
-
Object
- Object
- Characterizable::Characteristic
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/characterizable.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prerequisite ⇒ Object
readonly
Returns the value of attribute prerequisite.
-
#trumps ⇒ Object
readonly
Returns the value of attribute trumps.
Instance Method Summary collapse
- #as_json ⇒ Object
- #characteristics ⇒ Object
- #effective?(universe, ignoring = nil) ⇒ Boolean
-
#initialize(base, name, options = {}, &block) ⇒ Characteristic
constructor
A new instance of Characteristic.
- #inspect ⇒ Object
- #known?(universe) ⇒ Boolean
- #potential?(universe) ⇒ Boolean
- #revealed?(universe) ⇒ Boolean
- #reveals(other_name, other_options = {}, &block) ⇒ Object
- #trumped?(universe, ignoring = nil) ⇒ Boolean
- #value(universe) ⇒ Object
Constructor Details
#initialize(base, name, options = {}, &block) ⇒ Characteristic
Returns a new instance of Characteristic.
166 167 168 169 170 171 172 173 |
# File 'lib/characterizable.rb', line 166 def initialize(base, name, = {}, &block) @base = base @name = name @trumps = Array.wrap .delete(:trumps) @prerequisite = .delete(:prerequisite) @options = Blockenspiel.invoke block, self if block_given? end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
161 162 163 |
# File 'lib/characterizable.rb', line 161 def base @base end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
162 163 164 |
# File 'lib/characterizable.rb', line 162 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
165 166 167 |
# File 'lib/characterizable.rb', line 165 def @options end |
#prerequisite ⇒ Object (readonly)
Returns the value of attribute prerequisite.
164 165 166 |
# File 'lib/characterizable.rb', line 164 def prerequisite @prerequisite end |
#trumps ⇒ Object (readonly)
Returns the value of attribute trumps.
163 164 165 |
# File 'lib/characterizable.rb', line 163 def trumps @trumps end |
Instance Method Details
#as_json ⇒ Object
174 175 176 |
# File 'lib/characterizable.rb', line 174 def as_json(*) { :name => name, :trumps => trumps, :prerequisite => prerequisite, :options => } end |
#characteristics ⇒ Object
180 181 182 |
# File 'lib/characterizable.rb', line 180 def characteristics base.characteristics end |
#effective?(universe, ignoring = nil) ⇒ Boolean
197 198 199 |
# File 'lib/characterizable.rb', line 197 def effective?(universe, ignoring = nil) known?(universe) and revealed? universe and not trumped? universe, ignoring end |
#inspect ⇒ Object
177 178 179 |
# File 'lib/characterizable.rb', line 177 def inspect "<Characterizable::Characteristic name=#{name.inspect} trumps=#{trumps.inspect} prerequisite=#{prerequisite.inspect} options=#{.inspect}>" end |
#known?(universe) ⇒ Boolean
191 192 193 |
# File 'lib/characterizable.rb', line 191 def known?(universe) not value(universe).nil? end |
#potential?(universe) ⇒ Boolean
194 195 196 |
# File 'lib/characterizable.rb', line 194 def potential?(universe) not known?(universe) and revealed? universe and not trumped? universe end |
#revealed?(universe) ⇒ Boolean
213 214 215 216 |
# File 'lib/characterizable.rb', line 213 def revealed?(universe) return true if prerequisite.nil? characteristics[prerequisite].effective? universe end |
#reveals(other_name, other_options = {}, &block) ⇒ Object
218 219 220 |
# File 'lib/characterizable.rb', line 218 def reveals(other_name, = {}, &block) base.has other_name, .merge(:prerequisite => name), &block end |
#trumped?(universe, ignoring = nil) ⇒ Boolean
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/characterizable.rb', line 200 def trumped?(universe, ignoring = nil) characteristics.each do |_, other| if other.trumps.include? name and not ignoring == other.name if trumps.include? other.name # special case: mutual trumping. current characteristic is trumped if its friend is otherwise effective and it is not otherwise effective return true if other.effective? universe, name and not effective? universe, other.name else return true if other.effective? universe end end end false end |
#value(universe) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/characterizable.rb', line 183 def value(universe) case universe when Hash universe[name] else universe.send name if universe.respond_to?(name) end end |