Class: Fancy

Inherits:
Object
  • Object
show all
Defined in:
lib/kittyverse/fancies.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#countObject

Returns the value of attribute count.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def count
  @count
end

#dateObject

Returns the value of attribute date.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def date
  @date
end

#descObject

Returns the value of attribute desc.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def desc
  @desc
end

#exclusiveObject

Returns the value of attribute exclusive.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def exclusive
  @exclusive
end

#idsObject

Returns the value of attribute ids.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def ids
  @ids
end

#keyObject

Returns the value of attribute key.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def key
  @key
end

#limitObject

Returns the value of attribute limit.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def name
  @name
end

#name_cnObject

Returns the value of attribute name_cn.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def name_cn
  @name_cn
end

#recipeObject

Returns the value of attribute recipe.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def recipe
  @recipe
end

#specialeditionObject

Returns the value of attribute specialedition.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def specialedition
  @specialedition
end

#time_endObject

Returns the value of attribute time_end.



72
73
74
# File 'lib/kittyverse/fancies.rb', line 72

def time_end
  @time_end
end

#time_startObject

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

.breedableObject

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

.eachObject



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

.exclusivesObject

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

.fanciesObject

“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_keyObject



4
# File 'lib/kittyverse/fancies.rb', line 4

def self.fancies_by_key()  @@fancies_by_key  ||= {}; end

.fancies_by_nameObject



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

.sizeObject

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_editionsObject

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

Returns:

  • (Boolean)


106
# File 'lib/kittyverse/fancies.rb', line 106

def count?()    @count; end

#exclusive?Boolean

Returns:

  • (Boolean)


98
# File 'lib/kittyverse/fancies.rb', line 98

def exclusive?()        @exclusive.nil? == false; end

#limit?Boolean

Returns:

  • (Boolean)


105
# File 'lib/kittyverse/fancies.rb', line 105

def limit?()    @limit; end

#locked?(today = Date.today) ⇒ Boolean

Returns:

  • (Boolean)


135
# File 'lib/kittyverse/fancies.rb', line 135

def locked?( today=Date.today ) !unlocked?( today ); end

#overflowObject

todo: check for count limit set - why? why not?



104
# File 'lib/kittyverse/fancies.rb', line 104

def overflow()  @count - @limit; end

#overflow?Boolean

Returns:

  • (Boolean)


103
# File 'lib/kittyverse/fancies.rb', line 103

def overflow?() @count && @limit && @count > @limit; end

#recipe?Boolean

Returns:

  • (Boolean)


101
# File 'lib/kittyverse/fancies.rb', line 101

def recipe?()           @recipe.nil? == false; end

#specialedition?Boolean Also known as: special_edition?

Returns:

  • (Boolean)


99
# File 'lib/kittyverse/fancies.rb', line 99

def specialedition?()   @specialedition.nil? == false; end

#time?Boolean

is fancy(recipe,specialedition) time windowed? true/false

Returns:

  • (Boolean)


108
# File 'lib/kittyverse/fancies.rb', line 108

def time?()     @time_start && @time_end; end

#time_daysObject



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?

Returns:

  • (Boolean)


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