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.
86 87 88 89 |
# File 'lib/kittyverse/fancies.rb', line 86 def initialize( **kwargs ) @exclusive = @specialedition = @recipe = nil update( kwargs ) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def count @count end |
#date ⇒ Object
Returns the value of attribute date.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def date @date end |
#desc ⇒ Object
Returns the value of attribute desc.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def desc @desc end |
#exclusive ⇒ Object
Returns the value of attribute exclusive.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def exclusive @exclusive end |
#ids ⇒ Object
Returns the value of attribute ids.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def ids @ids end |
#key ⇒ Object
Returns the value of attribute key.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def key @key end |
#limit ⇒ Object
Returns the value of attribute limit.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def limit @limit end |
#name ⇒ Object
Returns the value of attribute name.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def name @name end |
#name_cn ⇒ Object
Returns the value of attribute name_cn.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def name_cn @name_cn end |
#recipe ⇒ Object
Returns the value of attribute recipe.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def recipe @recipe end |
#specialedition ⇒ Object
Returns the value of attribute specialedition.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def specialedition @specialedition end |
#time_end ⇒ Object
Returns the value of attribute time_end.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def time_end @time_end end |
#time_start ⇒ Object
Returns the value of attribute time_start.
72 73 74 |
# File 'lib/kittyverse/fancies.rb', line 72 def time_start @time_start end |
Class Method Details
.[](key) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kittyverse/fancies.rb', line 31 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?
60 61 62 63 |
# File 'lib/kittyverse/fancies.rb', line 60 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
43 44 45 46 47 |
# File 'lib/kittyverse/fancies.rb', line 43 def self.each @@fancies_by_key.each do |(key,fancy)| yield( fancy ) end end |
.exclusives ⇒ Object
exclusive fancies
53 54 55 |
# File 'lib/kittyverse/fancies.rb', line 53 def self.exclusives # exclusive fancies @@fancies_by_key.values.select { |fancy| fancy.exclusive? } end |
.fancies ⇒ Object
“normal” fancies
56 57 58 |
# File 'lib/kittyverse/fancies.rb', line 56 def self.fancies # "normal" fancies @@fancies_by_key.values.select { |fancy| fancy.recipe? } end |
.fancies_by_key ⇒ Object
4 |
# File 'lib/kittyverse/fancies.rb', line 4 def self.fancies_by_key() @@fancies_by_key ||= {}; end |
.fancies_by_name ⇒ Object
5 |
# File 'lib/kittyverse/fancies.rb', line 5 def self.fancies_by_name() @@fancies_by_name ||= {}; end |
.find_by(**kwargs) ⇒ Object
add “generic” convenience find helper
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kittyverse/fancies.rb', line 20 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
7 8 9 10 |
# File 'lib/kittyverse/fancies.rb', line 7 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
12 13 14 15 16 17 |
# File 'lib/kittyverse/fancies.rb', line 12 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?
66 |
# File 'lib/kittyverse/fancies.rb', line 66 def self.size() @@fancies_by_key.size; end |
.special_editions ⇒ Object
special edition fancies
50 51 52 |
# File 'lib/kittyverse/fancies.rb', line 50 def self.special_editions # special edition fancies @@fancies_by_key.values.select { |fancy| fancy.special_edition? } end |
Instance Method Details
#count? ⇒ Boolean
106 |
# File 'lib/kittyverse/fancies.rb', line 106 def count?() @count; end |
#exclusive? ⇒ Boolean
98 |
# File 'lib/kittyverse/fancies.rb', line 98 def exclusive?() @exclusive.nil? == false; end |
#limit? ⇒ Boolean
105 |
# File 'lib/kittyverse/fancies.rb', line 105 def limit?() @limit; end |
#locked?(today = Date.today) ⇒ Boolean
135 |
# File 'lib/kittyverse/fancies.rb', line 135 def locked?( today=Date.today ) !unlocked?( today ); end |
#overflow ⇒ Object
todo: check for count limit set - why? why not?
104 |
# File 'lib/kittyverse/fancies.rb', line 104 def overflow() @count - @limit; end |
#overflow? ⇒ Boolean
103 |
# File 'lib/kittyverse/fancies.rb', line 103 def overflow?() @count && @limit && @count > @limit; end |
#recipe? ⇒ Boolean
101 |
# File 'lib/kittyverse/fancies.rb', line 101 def recipe?() @recipe.nil? == false; end |
#specialedition? ⇒ Boolean Also known as: special_edition?
99 |
# File 'lib/kittyverse/fancies.rb', line 99 def specialedition?() @specialedition.nil? == false; end |
#time? ⇒ Boolean
is fancy(recipe,specialedition) time windowed? true/false
108 |
# File 'lib/kittyverse/fancies.rb', line 108 def time?() @time_start && @time_end; end |
#time_days ⇒ Object
110 |
# File 'lib/kittyverse/fancies.rb', line 110 def time_days() (@time_end.jd - @time_start.jd) + 1; end |
#unlocked?(today = Date.today) ⇒ Boolean Also known as: breedable?
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/kittyverse/fancies.rb', line 113 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
91 92 93 94 95 96 |
# File 'lib/kittyverse/fancies.rb', line 91 def update( **kwargs ) kwargs.each do |name,value| send( "#{name}=", value ) ## use "regular" plain/classic attribute setter end self ## return self for chaining end |