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.



88
89
90
91
# File 'lib/kittyverse/fancies.rb', line 88

def initialize( **kwargs )
  @exclusive = @specialedition = @recipe = nil
  update( kwargs )
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def count
  @count
end

#dateObject

Returns the value of attribute date.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def date
  @date
end

#descObject

Returns the value of attribute desc.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def desc
  @desc
end

#exclusiveObject

Returns the value of attribute exclusive.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def exclusive
  @exclusive
end

#idsObject

Returns the value of attribute ids.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def ids
  @ids
end

#keyObject

Returns the value of attribute key.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def key
  @key
end

#limitObject

Returns the value of attribute limit.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def name
  @name
end

#name_cnObject

Returns the value of attribute name_cn.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def name_cn
  @name_cn
end

#recipeObject

Returns the value of attribute recipe.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def recipe
  @recipe
end

#specialeditionObject

Returns the value of attribute specialedition.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def specialedition
  @specialedition
end

#time_endObject

Returns the value of attribute time_end.



74
75
76
# File 'lib/kittyverse/fancies.rb', line 74

def time_end
  @time_end
end

#time_startObject

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

.breedableObject

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

.eachObject



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

.exclusivesObject

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

.fanciesObject

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



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

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

.fancies_by_nameObject



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

.sizeObject

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_editionsObject

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

Returns:

  • (Boolean)


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

def count?()    @count; end

#exclusive?Boolean

Returns:

  • (Boolean)


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

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

#limit?Boolean

Returns:

  • (Boolean)


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

def limit?()    @limit; end

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

Returns:

  • (Boolean)


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

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

#overflowObject

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



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

def overflow()  @count - @limit; end

#overflow?Boolean

Returns:

  • (Boolean)


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

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

#recipe?Boolean

Returns:

  • (Boolean)


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

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

#specialedition?Boolean Also known as: special_edition?

Returns:

  • (Boolean)


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

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

#time?Boolean

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

Returns:

  • (Boolean)


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

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

#time_daysObject



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?

Returns:

  • (Boolean)


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