class Fancy

Attributes

count[RW]
date[RW]
desc[RW]
exclusive[RW]
ids[RW]
key[RW]
limit[RW]
name[RW]
name_cn[RW]
recipe[RW]
specialedition[RW]
time_end[RW]
time_start[RW]

Public Class Methods

[]( key ) click to toggle source
# 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() click to toggle source
# 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() { |fancy| ... } click to toggle source
# File lib/kittyverse/fancies.rb, line 43
def self.each
  @@fancies_by_key.each do |(key,fancy)|
    yield( fancy )
  end
end
exclusives() click to toggle source
# File lib/kittyverse/fancies.rb, line 53
def self.exclusives        # exclusive fancies
  @@fancies_by_key.values.select { |fancy| fancy.exclusive? }
end
fancies() click to toggle source
# File lib/kittyverse/fancies.rb, line 56
def self.fancies           # "normal" fancies
  @@fancies_by_key.values.select { |fancy| fancy.recipe? }
end
fancies_by_key() click to toggle source
# File lib/kittyverse/fancies.rb, line 4
def self.fancies_by_key()  @@fancies_by_key  ||= {}; end
fancies_by_name() click to toggle source
# File lib/kittyverse/fancies.rb, line 5
def self.fancies_by_name() @@fancies_by_name ||= {}; end
find_by( **kwargs ) click to toggle source

add “generic” convenience find helper

# 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 ) click to toggle source
# 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 ) click to toggle source
# 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
new( **kwargs ) click to toggle source
# File lib/kittyverse/fancies.rb, line 86
def initialize( **kwargs )
  @exclusive = @specialedition = @recipe = nil
  update( kwargs )
end
size() click to toggle source
# File lib/kittyverse/fancies.rb, line 66
def self.size() @@fancies_by_key.size; end
special_editions() click to toggle source
# File lib/kittyverse/fancies.rb, line 50
def self.special_editions  # special edition fancies
  @@fancies_by_key.values.select { |fancy| fancy.special_edition? }
end

Public Instance Methods

breedable?( today=Date.today )
Alias for: unlocked?
count?() click to toggle source
# File lib/kittyverse/fancies.rb, line 106
def count?()    @count; end
exclusive?() click to toggle source
# File lib/kittyverse/fancies.rb, line 98
def exclusive?()        @exclusive.nil? == false; end
limit?() click to toggle source
# File lib/kittyverse/fancies.rb, line 105
def limit?()    @limit; end
locked?( today=Date.today ) click to toggle source
# File lib/kittyverse/fancies.rb, line 135
def locked?( today=Date.today ) !unlocked?( today ); end
overflow() click to toggle source
# File lib/kittyverse/fancies.rb, line 104
def overflow()  @count - @limit; end
overflow?() click to toggle source
# File lib/kittyverse/fancies.rb, line 103
def overflow?() @count && @limit && @count > @limit; end
recipe?() click to toggle source
# File lib/kittyverse/fancies.rb, line 101
def recipe?()           @recipe.nil? == false; end
special_edition?()
Alias for: specialedition?
specialedition?() click to toggle source
# File lib/kittyverse/fancies.rb, line 99
def specialedition?()   @specialedition.nil? == false; end
Also aliased as: special_edition?
time?() click to toggle source
# File lib/kittyverse/fancies.rb, line 108
def time?()     @time_start && @time_end; end
time_days() click to toggle source
# File lib/kittyverse/fancies.rb, line 110
def time_days() (@time_end.jd - @time_start.jd) + 1; end
unlocked?( today=Date.today ) click to toggle source
# 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
Also aliased as: breedable?
update( **kwargs ) click to toggle source
# 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