Class: Cattribute
- Inherits:
-
Object
- Object
- Cattribute
- Defined in:
- lib/kittyverse/cattributes.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#traits ⇒ Object
Returns the value of attribute traits.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .[](name) ⇒ Object
- .cattributes_by_name ⇒ Object
-
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper.
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Cattribute
constructor
A new instance of Cattribute.
-
#tt ⇒ Object
autofill cattributes.
- #update(**kwargs) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Cattribute
Returns a new instance of Cattribute.
34 35 36 |
# File 'lib/kittyverse/cattributes.rb', line 34 def initialize( **kwargs ) update( kwargs ) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def count @count end |
#key ⇒ Object
Returns the value of attribute key.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def name @name end |
#recipe ⇒ Object
Returns the value of attribute recipe.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def recipe @recipe end |
#traits ⇒ Object
Returns the value of attribute traits.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def traits @traits end |
#type ⇒ Object
Returns the value of attribute type.
27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 27 def type @type end |
Class Method Details
.[](name) ⇒ Object
23 |
# File 'lib/kittyverse/cattributes.rb', line 23 def self.[]( name ) find_by_name( name ); end |
.cattributes_by_name ⇒ Object
5 |
# File 'lib/kittyverse/cattributes.rb', line 5 def self.cattributes_by_name() @@cattributes_by_name ||= {}; end |
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper
14 15 16 17 18 19 20 21 |
# File 'lib/kittyverse/cattributes.rb', line 14 def self.find_by( **kwargs ) if kwargs[ :name ] find_by_name( kwargs[ :name ] ) else ## todo/fix: throw argument except!!! nil end end |
.find_by_name(name) ⇒ Object
7 8 9 10 11 |
# File 'lib/kittyverse/cattributes.rb', line 7 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) @@cattributes_by_name[ name.downcase.to_s ] end |
Instance Method Details
#tt ⇒ Object
autofill cattributes
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/kittyverse/cattributes.rb', line 48 TraitType.each do |tt| key = tt.key puts "key: #{key}" tt.cattributes ||= [] ## if nil make sure it's an empty array when starting ## pp tt next if [:secret, :prestige].include?( key) tt.traits.each do |t| ## 1) skip "unnamed" traits next if t.name.nil? pp t.name ## 2) special case for totesbasic - one cattribute, three traits ## (that is, Totesbasic 1, Totesbasic 2, Totesbasic 3) if TOTESBASIC.include?( t.name ) if t.name == TOTESBASIC.first t1 = Traits[ TOTESBASIC[0] ] t2 = Traits[ TOTESBASIC[1] ] t3 = Traits[ TOTESBASIC[2] ] cattribute = Cattribute.new( key: 'totesbasic'.to_sym, name: 'Totesbasic', type: tt, traits: [t1,t2,t3] ) else next ## skip all other totesbasic traits end else cattribute = Cattribute.new( key: t.name.to_sym, name: t.name, type: tt, traits: [t] ) ## pp cattribute end tt.cattributes << cattribute cattributes_by_name[ cattribute.name.downcase ] = cattribute end end |
#update(**kwargs) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/kittyverse/cattributes.rb', line 38 def update( **kwargs ) kwargs.each do |name,value| send( "#{name}=", value ) ## use "regular" plain/classic attribute setter end self ## return self for chaining end |