Class: Trait
- Inherits:
-
Object
- Object
- Trait
- Defined in:
- lib/kittyverse/traits.rb
Instance Attribute Summary collapse
-
#kai ⇒ Object
Returns the value of attribute kai.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .[](key) ⇒ Object
-
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helpers.
- .find_by_code(code) ⇒ Object
- .find_by_name(name) ⇒ Object
- .traits_by_code ⇒ Object
- .traits_by_name ⇒ Object
Instance Method Summary collapse
-
#base? ⇒ Boolean
base level 0 - no mutation.
- #binary ⇒ Object (also: #bin)
- #code ⇒ Object
-
#initialize(**kwargs) ⇒ Trait
constructor
A new instance of Trait.
-
#m1? ⇒ Boolean
m1 - mutation level 1.
-
#m2? ⇒ Boolean
m2 - mutation level 2.
-
#m3? ⇒ Boolean
m3 - mutation level 3.
-
#m4? ⇒ Boolean
m4 - mutation level 4.
- #num ⇒ Object
- #tier(format = :num) ⇒ Object (also: #level, #m)
- #tier_roman ⇒ Object
- #update(**kwargs) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Trait
Returns a new instance of Trait.
50 51 52 |
# File 'lib/kittyverse/traits.rb', line 50 def initialize( **kwargs ) update( kwargs ) end |
Instance Attribute Details
#kai ⇒ Object
Returns the value of attribute kai.
46 47 48 |
# File 'lib/kittyverse/traits.rb', line 46 def kai @kai end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/kittyverse/traits.rb', line 46 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
46 47 48 |
# File 'lib/kittyverse/traits.rb', line 46 def type @type end |
Class Method Details
.[](key) ⇒ Object
36 37 38 39 40 41 42 |
# 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) ⇒ Object
add “generic” convenience find helpers
25 26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
7 8 9 10 11 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 |
.traits_by_code ⇒ Object
4 |
# File 'lib/kittyverse/traits.rb', line 4 def self.traits_by_code() @@traits_by_code ||= {}; end |
.traits_by_name ⇒ Object
5 |
# File 'lib/kittyverse/traits.rb', line 5 def self.traits_by_name() @@traits_by_name ||= {}; end |
Instance Method Details
#base? ⇒ Boolean
base level 0 - no mutation
83 |
# File 'lib/kittyverse/traits.rb', line 83 def base?() tier == 0; end |
#binary ⇒ Object Also known as: bin
63 |
# File 'lib/kittyverse/traits.rb', line 63 def binary() "%05b" % num; end |
#code ⇒ Object
62 |
# File 'lib/kittyverse/traits.rb', line 62 def code() "#{@type.code}#{Kai::CODE[@kai]}"; end |
#m1? ⇒ Boolean
m1 - mutation level 1
84 |
# File 'lib/kittyverse/traits.rb', line 84 def m1?() tier == 1; end |
#m2? ⇒ Boolean
m2 - mutation level 2
85 |
# File 'lib/kittyverse/traits.rb', line 85 def m2?() tier == 2; end |
#m3? ⇒ Boolean
m3 - mutation level 3
86 |
# File 'lib/kittyverse/traits.rb', line 86 def m3?() tier == 3; end |
#m4? ⇒ Boolean
m4 - mutation level 4
87 |
# File 'lib/kittyverse/traits.rb', line 87 def m4?() tier == 4; end |
#num ⇒ Object
61 |
# File 'lib/kittyverse/traits.rb', line 61 def num() Kai::NUMBER[@kai]; end |
#tier(format = :num) ⇒ Object Also known as: level, m
67 68 69 70 71 72 73 74 75 76 |
# 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 ⇒ Object
78 |
# File 'lib/kittyverse/traits.rb', line 78 def tier_roman() tier(:roman); end |
#update(**kwargs) ⇒ Object
54 55 56 57 58 59 |
# 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 |