Class: TimelineFanciesPage

Inherits:
Object
  • Object
show all
Defined in:
lib/kittypedia/pages/timeline_fancies.rb

Constant Summary collapse

HEADER =
<<TXT
[2021](#2021) •
[2020](#2020) •
[2019](#2019) •
[2018](#2018) •
[2017](#2017)

# Updates - Fancy / Exclusive / Special Edition Cats - Timeline

see <https://updates.cryptokitties.co>


TXT
FANCY_BY_DATE =

sort fancies by date - latest first / reverse chronological order

begin
  fancies = []
  Fancy.each { |fancy| fancies << fancy }
  ## note: sort by recipe date if present?
  fancies.sort do |l,r|
    r.date <=> l.date
  end
end

Instance Method Summary collapse

Instance Method Details

#buildObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 33

def build
  buf = ""
  buf << HEADER

  special_editions = Fancy.special_editions
  exclusives       = Fancy.exclusives
  fancies          = Fancy.fancies

  buf << "## Special Edition Cats (#{special_editions.size})"
  buf << "\n\n"
  buf << build_fancies( special_editions )
  buf << "\n\n"
  buf << build_fancies_media( special_editions )
  buf << "\n\n"

  buf << "## Exclusive Cats (#{exclusives.size})"
  buf << "\n\n"
  buf << build_fancies( exclusives )
  buf << "\n\n"
  buf << build_fancies_media( exclusives )
  buf << "\n\n"

  buf << "## Fancy Cats (#{fancies.size})"
  buf << "\n\n"
  buf << build_fancies( fancies )
  buf << "\n\n"
  buf << build_fancies_media( fancies )
  buf << "\n\n"

##################
## step 2 - add fancy cat details / chronic

month = nil
year  = nil
last_date = nil

## start of kitties blockchain / genesis
genesisdate = Date.new( 2017, 11, 23)   ## 2017-11-23


FANCY_BY_DATE.each do |fancy|

  key  = fancy.key
  date = fancy.date

  if year != date.year
    buf << "\n"
    buf << "\n"
    buf << "## #{date.year}"
    buf << "\n"
  end

  if month != date.month
    buf << "\n"
    buf << "### #{date.strftime( '%B')}"
    buf << "\n"
  end

  year  = date.year
  month = date.month


  if last_date != date
    buf << "\n"
    buf << date.strftime( '%b %-d, %Y')

    day_count = (date.jd - genesisdate.jd)+1
    buf << " (#{day_count}d)"
    buf << "\n"
  end
  last_date = date


  ## add anchor name
  buf << %Q{\n<a name="#{fancy.key}">}
  buf << "\n\n"


  line = ""
  name = ""

  line << "- "
  if fancy.special_edition?
    line << "Special Edition "
  elsif fancy.exclusive?
    line << "Exclusive "
  else
  end


  name << fancy.name
  name << " (#{fancy.name_cn})"  if fancy.name_cn   # add chinese name if present

  line << "[**#{name}**]"
  line << "(#{kitties_fancy_search_url( fancy )})"


  line << " ("
  line << build_fancy_counter(fancy)

  if fancy.ids
    id_links = fancy.ids.map { |id| "[##{id}](#{kitties_kitty_url(id)})" }
    line << " - #{id_links.join(', ')}"
  end
  line << ")"



  if fancy.special_edition?
    line << " Fancy Cat released"
    line << " -- #{fancy.desc}"    if fancy.desc
    line << "."
    line << " #Fancy Cat #Special Edition"
  elsif fancy.exclusive?
    line << " Fancy Cat released"
    line << " -- #{fancy.desc}"    if fancy.desc
    line << "."
    line << " #Fancy Cat #Exclusive"
  else
    line << " Fancy Cat discovered"
    line << " -- #{fancy.desc}"    if fancy.desc
    line << "."
    line << " #Fancy Cat"
  end

  buf << line
  buf << "\n"


  ## special case for time-windows special editions
  if fancy.specialedition? && fancy.time?
    time_window = build_time_window( fancy )
    buf << "  - #{time_window}"
    buf << "\n"
  end


  if fancy.recipe?
    buf << "  - **#{fancy.recipe.traits.size}** traits"
    buf << " + **#{fancy.recipe.variants.size}** variants"  if fancy.recipe.variants

    if fancy.recipe.time?   ## time windowed recipe
      time_window = build_time_window( fancy.recipe )
      buf << " - #{time_window}"
    end
    buf << ":"
    buf << "\n"

    ## traits:
    fancy.recipe.traits.each do |trait_keys|
        buf << "    - "
        buf << build_traits( trait_keys )
        buf << "\n"
    end

    if fancy.recipe.variants
        fancy.recipe.variants.each do |variant_key,variant_h|
          buf << "      - **#{variant_h[:name]}** (#{variant_h[:count]}), **#{variant_h[:traits].size}** trait:\n"
          variant_h[:traits].each do |trait_keys|
            buf << "        - "
            buf << build_traits( trait_keys )
            buf << "\n"
          end
        end
    end
  end

  buf << "\n"
  buf << build_fancy_media( fancy )
  buf << "\n"
end
  buf

end

#build_fancies(fancies) ⇒ Object



293
294
295
296
297
298
299
300
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 293

def build_fancies( fancies )
  buf = ""
  fancies.each do |fancy|
    buf << build_fancy( fancy )
    buf << "\n"
  end
  buf
end

#build_fancies_media(fancies) ⇒ Object



322
323
324
325
326
327
328
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 322

def build_fancies_media( fancies )
  buf = ""
  fancies.each do |fancy|
    buf << build_fancy_media( fancy )
  end
  buf
end

#build_fancy(fancy) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 275

def build_fancy( fancy )
  name = ""
  name << fancy.name
  name << " (#{fancy.name_cn})"   if fancy.name_cn   # add chinese name if present

  line = "[**#{name}**]"
  ## line << "(#{kitties_fancy_search_url( fancy )})"
  line << "(##{fancy.key})"

  line << " ("
  line << build_fancy_counter( fancy, show_time: true )
  line << ")"

  line
end

#build_fancy_counter(fancy, show_time: false) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 225

def build_fancy_counter( fancy, show_time: false )
  buf = ""

  if fancy.recipe?
    if fancy.recipe.time?   ## time windowed recipe
      if fancy.recipe.time_end >= Date.today
        buf << "![](#{media_icon_url(:unlocked)})"
        if fancy.count     # add count if present/known
          buf << "#{fancy.count}+"
        else
          buf << "?"
        end
        if show_time
          buf << "/Till: #{fancy.recipe.time_end.strftime( '%b %-d %Y')}"
        end
      else
        buf << "#{fancy.count ? fancy.count : '?'}"     # add count if present/known
      end
    elsif fancy.recipe &&
          fancy.recipe.time_start &&   ## time window BUT unknown end date
          fancy.recipe.time_end.nil?
      if fancy.count     # add count if present/known
        buf << "#{fancy.count}+"
      else
        buf << "?"
      end
    else  ## assume limit
      if fancy.count && fancy.count < fancy.limit
        buf << "![](#{media_icon_url(:unlocked)})"
        if fancy.count <= 0
          buf << '?'
        else
          buf << "#{fancy.count}+"
        end
        buf << "/#{fancy.limit}"     # add limit if present/known
      else
        buf << "#{fancy.limit ? fancy.limit : '?'}"
        buf << "+#{fancy.overflow}"     if fancy.overflow?
      end
    end
  else
    ## note: fow now exclusive and specialeditions always have a limit
    ##          and do NOT use counts   (- use count for (time-windowed) specialeditions - why? why not?)
    buf << "#{fancy.limit ? fancy.limit : '?'}"     # add limit if present/known
  end
  buf
end

#build_fancy_media(fancy) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 303

def build_fancy_media( fancy )
  buf = ""
  if fancy.recipe && fancy.recipe.variants
    fancy.recipe.variants.each do |variant_key,variant_h|
      name = "#{fancy.name} #{variant_h[:name]}"

      buf << %Q{![#{name}](#{media_fancy_pic_url( fancy.key, variant_key )} "#{name}")}
      buf << "\n"
    end
  else
    name = "#{fancy.name}"
    name << " (#{fancy.name_cn})" if fancy.name_cn

    buf << %Q{![#{name}](#{media_fancy_pic_url( fancy.key )} "#{name}")}
    buf << "\n"
  end
  buf
end

#build_time_window(o) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 210

def build_time_window( o )
  buf = ""
  if o.time_start.year == o.time_end.year
    buf << o.time_start.strftime( '%b %-d')
  else   # include year
    buf << o.time_start.strftime( '%b %-d %Y')
  end

  buf << " - "
  buf << o.time_end.strftime( '%b %-d %Y')
  buf << " (#{o.time_days}d)"
  buf
end

#build_trait(key) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 332

def build_trait( key )
  puts "lookup trait >#{key}<"
  trait = Trait[ key ]
  ## pp trait
  if trait.nil?
    puts "!! ERROR: cannot find trait with key: >#{key}<"
    exit 1
  end

  if key =~ /[A-Z]{2}[0-9]{2}/   # if code e.g. WE20 - keep as is
     line = "**#{key}** #{trait.tier_roman} "

     [line, trait.type.name]
  else
    # rec[:name] = name
    # rec[:kai]  = kai
    # rec[:code] = code
    # rec[:type] = key   ## todo - use trait instead of type  (use string not symbol?) - why? why not?

    line = ""
    line << "**#{trait.name}** #{trait.tier_roman} "
    line << "("
    line << trait.code
    line << ")"

    [line, trait.type.name]
  end
end

#build_traits(key_or_keys) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/kittypedia/pages/timeline_fancies.rb', line 361

def build_traits( key_or_keys )
  pp key_or_keys
  if key_or_keys.is_a? Array
    keys = key_or_keys
    tt = ""   ## last trait type  (assume all trait types are the same for now)
    t = keys.map do |key|
      t, tt = build_trait( key )
      t
    end.join(', ')
  else
    key = key_or_keys
    t, tt = build_trait( key )
  end
  "#{t} - #{tt}"   # trait (t) - trait type (tt)
end