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.
42 43 44 |
# File 'lib/kittyverse/cattributes.rb', line 42 def initialize( **kwargs ) update( kwargs ) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def count @count end |
#key ⇒ Object
Returns the value of attribute key.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def name @name end |
#recipe ⇒ Object
Returns the value of attribute recipe.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def recipe @recipe end |
#traits ⇒ Object
Returns the value of attribute traits.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def traits @traits end |
#type ⇒ Object
Returns the value of attribute type.
35 36 37 |
# File 'lib/kittyverse/cattributes.rb', line 35 def type @type end |
Class Method Details
.[](name) ⇒ Object
31 |
# File 'lib/kittyverse/cattributes.rb', line 31 def self.[]( name ) find_by_name( name ); end |
.cattributes_by_name ⇒ Object
13 |
# File 'lib/kittyverse/cattributes.rb', line 13 def self.cattributes_by_name() @@cattributes_by_name ||= {}; end |
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper
22 23 24 25 26 27 28 29 |
# File 'lib/kittyverse/cattributes.rb', line 22 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
15 16 17 18 19 |
# File 'lib/kittyverse/cattributes.rb', line 15 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
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 95 96 97 98 99 100 101 102 |
# File 'lib/kittyverse/cattributes.rb', line 56 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
46 47 48 49 50 51 |
# File 'lib/kittyverse/cattributes.rb', line 46 def update( **kwargs ) kwargs.each do |name,value| send( "#{name}=", value ) ## use "regular" plain/classic attribute setter end self ## return self for chaining end |