Class: Fancy
- Inherits:
-
Object
- Object
- Fancy
- Defined in:
- lib/kittyverse/fancies.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#date ⇒ Object
Returns the value of attribute date.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#exclusive ⇒ Object
Returns the value of attribute exclusive.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#key ⇒ Object
Returns the value of attribute key.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_cn ⇒ Object
Returns the value of attribute name_cn.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#specialedition ⇒ Object
Returns the value of attribute specialedition.
-
#time_end ⇒ Object
Returns the value of attribute time_end.
-
#time_start ⇒ Object
Returns the value of attribute time_start.
Class Method Summary collapse
- .[](key) ⇒ Object
-
.breedable ⇒ Object
todo: find a better name (or add alias) e.g.
- .each ⇒ Object
-
.exclusives ⇒ Object
exclusive fancies.
-
.fancies ⇒ Object
“normal” fancies.
- .fancies_by_key ⇒ Object
- .fancies_by_name ⇒ Object
-
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper.
- .find_by_key(key) ⇒ Object
- .find_by_name(name) ⇒ Object
-
.size ⇒ Object
todo: add length alias too? why? why not?.
-
.special_editions ⇒ Object
special edition fancies.
Instance Method Summary collapse
- #count? ⇒ Boolean
- #exclusive? ⇒ Boolean
-
#initialize(**kwargs) ⇒ Fancy
constructor
A new instance of Fancy.
- #limit? ⇒ Boolean
- #locked?(today = Date.today) ⇒ Boolean
-
#overflow ⇒ Object
todo: check for count limit set - why? why not?.
- #overflow? ⇒ Boolean
- #recipe? ⇒ Boolean
- #specialedition? ⇒ Boolean (also: #special_edition?)
-
#time? ⇒ Boolean
is fancy(recipe,specialedition) time windowed? true/false.
- #time_days ⇒ Object
- #unlocked?(today = Date.today) ⇒ Boolean (also: #breedable?)
- #update(**kwargs) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Fancy
Returns a new instance of Fancy.
88 89 90 91 |
# File 'lib/kittyverse/fancies.rb', line 88 def initialize( **kwargs ) @exclusive = @specialedition = @recipe = nil update( kwargs ) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def count @count end |
#date ⇒ Object
Returns the value of attribute date.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def date @date end |
#desc ⇒ Object
Returns the value of attribute desc.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def desc @desc end |
#exclusive ⇒ Object
Returns the value of attribute exclusive.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def exclusive @exclusive end |
#ids ⇒ Object
Returns the value of attribute ids.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def ids @ids end |
#key ⇒ Object
Returns the value of attribute key.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def key @key end |
#limit ⇒ Object
Returns the value of attribute limit.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def limit @limit end |
#name ⇒ Object
Returns the value of attribute name.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def name @name end |
#name_cn ⇒ Object
Returns the value of attribute name_cn.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def name_cn @name_cn end |
#recipe ⇒ Object
Returns the value of attribute recipe.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def recipe @recipe end |
#specialedition ⇒ Object
Returns the value of attribute specialedition.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def specialedition @specialedition end |
#time_end ⇒ Object
Returns the value of attribute time_end.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def time_end @time_end end |
#time_start ⇒ Object
Returns the value of attribute time_start.
74 75 76 |
# File 'lib/kittyverse/fancies.rb', line 74 def time_start @time_start end |
Class Method Details
.[](key) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kittyverse/fancies.rb', line 33 def self.[]( key ) if key.is_a? Symbol ## e.g. :genesis, :bugcat, etc. f = find_by_key( key ) f = find_by_name( key ) if f.nil? ## try fancy name next - why? why not? f else ## assume string f = find_by_name( key ) ## search by key next - why? why not? f end end |
.breedable ⇒ Object
todo: find a better name (or add alias) e.g. use unlocked why? why not?
62 63 64 65 |
# File 'lib/kittyverse/fancies.rb', line 62 def self.breedable ## todo: find a better name (or add alias) e.g. use unlocked why? why not? today = Date.today @@fancies_by_key.values.select { |fancy| fancy.breedable?( today ) } end |
.each ⇒ Object
45 46 47 48 49 |
# File 'lib/kittyverse/fancies.rb', line 45 def self.each @@fancies_by_key.each do |(key,fancy)| yield( fancy ) end end |
.exclusives ⇒ Object
exclusive fancies
55 56 57 |
# File 'lib/kittyverse/fancies.rb', line 55 def self.exclusives # exclusive fancies @@fancies_by_key.values.select { |fancy| fancy.exclusive? } end |
.fancies ⇒ Object
“normal” fancies
58 59 60 |
# File 'lib/kittyverse/fancies.rb', line 58 def self.fancies # "normal" fancies @@fancies_by_key.values.select { |fancy| fancy.recipe? } end |
.fancies_by_key ⇒ Object
6 |
# File 'lib/kittyverse/fancies.rb', line 6 def self.fancies_by_key() @@fancies_by_key ||= {}; end |
.fancies_by_name ⇒ Object
7 |
# File 'lib/kittyverse/fancies.rb', line 7 def self.fancies_by_name() @@fancies_by_name ||= {}; end |
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kittyverse/fancies.rb', line 22 def self.find_by( **kwargs ) if kwargs[ :key ] find_by_key( kwargs[ :key ] ) elsif kwargs[ :name ] find_by_name( kwargs[ :name] ) else ## todo/fix: throw argument except!!! nil end end |
.find_by_key(key) ⇒ Object
9 10 11 12 |
# File 'lib/kittyverse/fancies.rb', line 9 def self.find_by_key( key ) ## note: use (always) a **symbol** for key lookup for now @@fancies_by_key[ key.downcase.to_sym ] end |
.find_by_name(name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/kittyverse/fancies.rb', line 14 def self.find_by_name( name ) ## note: allow string AND symbols (thus, use .to_s !!!) ## allow spaces e.g. Bug Cat is the same as BugCat ## note: downcase name e.g. allow BugCat too (not just Bug Cat) @@fancies_by_name[ name.gsub( / /, '' ).downcase.to_s ] end |
.size ⇒ Object
todo: add length alias too? why? why not?
68 |
# File 'lib/kittyverse/fancies.rb', line 68 def self.size() @@fancies_by_key.size; end |
.special_editions ⇒ Object
special edition fancies
52 53 54 |
# File 'lib/kittyverse/fancies.rb', line 52 def self.special_editions # special edition fancies @@fancies_by_key.values.select { |fancy| fancy.special_edition? } end |
Instance Method Details
#count? ⇒ Boolean
108 |
# File 'lib/kittyverse/fancies.rb', line 108 def count?() @count; end |
#exclusive? ⇒ Boolean
100 |
# File 'lib/kittyverse/fancies.rb', line 100 def exclusive?() @exclusive.nil? == false; end |
#limit? ⇒ Boolean
107 |
# File 'lib/kittyverse/fancies.rb', line 107 def limit?() @limit; end |
#locked?(today = Date.today) ⇒ Boolean
137 |
# File 'lib/kittyverse/fancies.rb', line 137 def locked?( today=Date.today ) !unlocked?( today ); end |
#overflow ⇒ Object
todo: check for count limit set - why? why not?
106 |
# File 'lib/kittyverse/fancies.rb', line 106 def overflow() @count - @limit; end |
#overflow? ⇒ Boolean
105 |
# File 'lib/kittyverse/fancies.rb', line 105 def overflow?() @count && @limit && @count > @limit; end |
#recipe? ⇒ Boolean
103 |
# File 'lib/kittyverse/fancies.rb', line 103 def recipe?() @recipe.nil? == false; end |
#specialedition? ⇒ Boolean Also known as: special_edition?
101 |
# File 'lib/kittyverse/fancies.rb', line 101 def specialedition?() @specialedition.nil? == false; end |
#time? ⇒ Boolean
is fancy(recipe,specialedition) time windowed? true/false
110 |
# File 'lib/kittyverse/fancies.rb', line 110 def time?() @time_start && @time_end; end |
#time_days ⇒ Object
112 |
# File 'lib/kittyverse/fancies.rb', line 112 def time_days() (@time_end.jd - @time_start.jd) + 1; end |
#unlocked?(today = Date.today) ⇒ Boolean Also known as: breedable?
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/kittyverse/fancies.rb', line 115 def unlocked?( today=Date.today ) if @recipe if @recipe.time? ## time windowed recipe if @recipe.time_end >= today true else false end else ## assume limit if @count && @count < @limit true else false end end else false end end |
#update(**kwargs) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/kittyverse/fancies.rb', line 93 def update( **kwargs ) kwargs.each do |name,value| send( "#{name}=", value ) ## use "regular" plain/classic attribute setter end self ## return self for chaining end |