class Trait
Attributes
kai[RW]
name[RW]
type[RW]
Public Class Methods
[]( key )
click to toggle source
# File lib/kittyverse/traits.rb, line 36 def self.[]( key ) if key.size == 4 && key =~ /^[A-Za-z]{2}[0-9]{2}$/ Trait.find_by_code( key ) else Trait.find_by_name( key ) end end
find_by( **kwargs )
click to toggle source
add “generic” convenience find helpers
# File lib/kittyverse/traits.rb, line 25 def self.find_by( **kwargs ) if kwargs[ :code ] find_by_code( kwargs[ :code] ) elsif kwargs[ :name ] find_by_name( kwargs[ :name ] ) else ## todo/fix: throw argument except!!! nil end end
find_by_code( code )
click to toggle source
# File lib/kittyverse/traits.rb, line 7 def self.find_by_code( code ) ## note: allow string AND symbols (thus, use .to_s) ## e.g. allow 'FU01', 'fu01', :fu01, :FU01, etc. @@traits_by_code[ code.upcase.to_s ] end
find_by_name( name )
click to toggle source
# File lib/kittyverse/traits.rb, line 13 def self.find_by_name( name ) ## note: allow string AND symbols (thus, use .to_s !!!) ## note: downcase name e.g. allow Savannah too (not just savannah) name = name.to_s.downcase name = ALT_TRAIT_NAMES[ name ] if ALT_TRAIT_NAMES[ name ] @@traits_by_name[ name ] end
new( **kwargs )
click to toggle source
# File lib/kittyverse/traits.rb, line 50 def initialize( **kwargs ) update( kwargs ) end
traits_by_code()
click to toggle source
# File lib/kittyverse/traits.rb, line 4 def self.traits_by_code() @@traits_by_code ||= {}; end
traits_by_name()
click to toggle source
# File lib/kittyverse/traits.rb, line 5 def self.traits_by_name() @@traits_by_name ||= {}; end
Public Instance Methods
base?()
click to toggle source
# File lib/kittyverse/traits.rb, line 83 def base?() tier == 0; end
binary()
click to toggle source
# File lib/kittyverse/traits.rb, line 63 def binary() "%05b" % num; end
Also aliased as: bin
code()
click to toggle source
# File lib/kittyverse/traits.rb, line 62 def code() "#{@type.code}#{Kai::CODE[@kai]}"; end
m1?()
click to toggle source
# File lib/kittyverse/traits.rb, line 84 def m1?() tier == 1; end
m2?()
click to toggle source
# File lib/kittyverse/traits.rb, line 85 def m2?() tier == 2; end
m3?()
click to toggle source
# File lib/kittyverse/traits.rb, line 86 def m3?() tier == 3; end
m4?()
click to toggle source
# File lib/kittyverse/traits.rb, line 87 def m4?() tier == 4; end
num()
click to toggle source
# File lib/kittyverse/traits.rb, line 61 def num() Kai::NUMBER[@kai]; end
tier( format=:num )
click to toggle source
# File lib/kittyverse/traits.rb, line 67 def tier( format=:num ) ## num => 0,1,2,3,4,nil : Integer|Nil ## roman => "","I","II","III","IIII",nil : String|Nil if format == :roman MUTATION_TIER_ROMAN[@kai] else ## assume integer num(ber) MUTATION_TIER[@kai] end end
tier_roman()
click to toggle source
# File lib/kittyverse/traits.rb, line 78 def tier_roman() tier(:roman); end
update( **kwargs )
click to toggle source
# File lib/kittyverse/traits.rb, line 54 def update( **kwargs ) kwargs.each do |name,value| send( "#{name}=", value ) ## use "regular" plain/classic attribute setter end self ## return self for chaining end