Class: TimelinePurrstigesPage

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

Constant Summary collapse

PRESTIGES_BY_DATE =
begin
  prestiges = []
  cattributes = TraitType.find_by_key( :prestige ).cattributes
  cattributes.each { |c| prestiges << c }
  ## note: sort by recipe date if present?
  prestiges.sort do |l,r|
    r.recipe.time_start <=> l.recipe.time_start
  end
end
HEADER =
<<TXT
[2021](#2021) •
[2020](#2020) •
[2019](#2019) •
[2018](#2018)

# Updates - Purrstige Trait Recipes / Formulas  - Timeline

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


TXT

Instance Method Summary collapse

Instance Method Details

#buildObject



29
30
31
32
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
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 29

def build
  buf = ""
  buf << HEADER

  buf << "## Purrstige Cattributes (#{PRESTIGES_BY_DATE.size})"
  buf << "\n\n"
  buf << "_Special traits for a limited time only bred through a recipe._"
  buf << "\n\n"
  buf << build_prestiges()
  buf << "\n\n\n"

  month = nil
year  = nil
last_date = nil

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


## buf << "## Purrstige Cattributes"
buf << "\n\n"


PRESTIGES_BY_DATE.each do |c|
  key =  c.key
  date = c.recipe.time_start

  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\n"
  end
  last_date = date


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


  name = ""
  name << c.name

  buf << "[**#{name}**]"
  buf << "(#{kitties_search_url( key )}) "

  buf << " (#{build_prestige_counter(c)})"      # add count(er)
  buf << ", "

  time_window = build_time_window( c.recipe )
  buf << "#{time_window}"
  buf << ", "


  buf << " **#{c.recipe.traits.size}** traits:"
  buf << "\n"

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

  buf << "\n\n"
end

  buf
end

#build_prestige(c) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 160

def build_prestige( c )
  name = ""
  name << c.name

  line = "[**#{name}**](##{c.key})"

  line << " (#{build_prestige_counter(c, show_time: true)})"    # add count(er)
  line
end

#build_prestige_counter(prestige, show_time: false) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 141

def build_prestige_counter( prestige, show_time: false )
  buf = ""

  if prestige.recipe.time_end && prestige.recipe.time_end >= Date.today
    buf << "![](#{media_icon_url(:unlocked)})"
    if prestige.count     # add count if present/known
      buf << "#{prestige.count}+"
    else
      buf << "?"
    end
    if show_time
      buf << "/Till: #{prestige.recipe.time_end.strftime( '%b %-d %Y')}"
    end
  else
    buf << "#{prestige.count ? prestige.count : '?'}"     # add count if present/known
  end
  buf
end

#build_prestigesObject



172
173
174
175
176
177
178
179
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 172

def build_prestiges
  buf = ""
  PRESTIGES_BY_DATE.each do |c|
    buf << build_prestige( c )
    buf << "\n"
  end
  buf
end

#build_time_window(o) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 122

def build_time_window( o )
  buf = ""

  if o.time_start && o.time_end   ## note: make sure start & end date present!!!
    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)"
  end

  buf
end

#build_trait(key) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 182

def build_trait( key )
  puts "lookup trait >#{key}<"
  trait = Trait[ key ]
  ## pp trait

  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



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/kittypedia/pages/timeline_purrstiges.rb', line 207

def build_traits( 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