Class: Ankit::Challenge::Progress

Inherits:
Object
  • Object
show all
Includes:
Ankit::CardHappening, Ankit::CardNaming, RoundCounting
Defined in:
lib/ankit/challenge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ankit::CardHappening

#make_happen

Methods included from Ankit::CardNaming

#card_wildcard_for, #to_card_name, #to_card_path

Methods included from EventTraversing

find_latest_event_for, find_latest_event_named, #latest_event_for

Methods included from EventFormatting

#format_as_score

Methods included from RoundCounting

#last_round, #latest_round, #next_round, #round_proceeded

Constructor Details

#initialize(session, slots) ⇒ Progress

Returns a new instance of Progress.



140
141
142
143
# File 'lib/ankit/challenge.rb', line 140

def initialize(session, slots)
  @session, @slots, @index = session, slots, 0
  @this_round = latest_round
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



138
139
140
# File 'lib/ankit/challenge.rb', line 138

def index
  @index
end

#sessionObject (readonly)

Returns the value of attribute session.



138
139
140
# File 'lib/ankit/challenge.rb', line 138

def session
  @session
end

#slotsObject (readonly)

Returns the value of attribute slots.



138
139
140
# File 'lib/ankit/challenge.rb', line 138

def slots
  @slots
end

#this_roundObject (readonly)

Returns the value of attribute this_round.



138
139
140
# File 'lib/ankit/challenge.rb', line 138

def this_round
  @this_round
end

Instance Method Details

#already_failed?Boolean

Returns:

  • (Boolean)


161
# File 'lib/ankit/challenge.rb', line 161

def already_failed?; current_slot.rating == :failed; end

#attackObject



163
164
165
166
# File 'lib/ankit/challenge.rb', line 163

def attack
  current_slot.rating = :attacking unless current_slot.rating
  self
end

#current_cardObject



155
# File 'lib/ankit/challenge.rb', line 155

def current_card; card_at(current_path); end

#current_pathObject



154
# File 'lib/ankit/challenge.rb', line 154

def current_path; current_slot.path; end

#current_slotObject



153
# File 'lib/ankit/challenge.rb', line 153

def current_slot; @slots[@index]; end

#failObject



168
169
170
171
172
173
174
175
176
177
# File 'lib/ankit/challenge.rb', line 168

def fail
  unless already_failed?
    last_slot = current_slot
    last_slot.rating = :failed
    last_slot.event = make_happen(FailCommand::EVENT_HAPPENING, to_card_name(current_path), this_round)
    session.failed_on(last_slot.event)
  end
  
  self
end

#indicatorObject



191
192
193
194
195
196
197
198
199
200
# File 'lib/ankit/challenge.rb', line 191

def indicator
  @slots.inject("") do |a, i|
    a += case i.rating
         when :failed; "x"
         when :passed; "o"
         when :attacking; "*"
         else;         "-"
         end
  end
end

#last_cardObject



152
# File 'lib/ankit/challenge.rb', line 152

def last_card; card_at(last_path); end

#last_pathObject



151
# File 'lib/ankit/challenge.rb', line 151

def last_path; last_slot.path; end

#last_slotObject



150
# File 'lib/ankit/challenge.rb', line 150

def last_slot; @slots[@index-1]; end

#maturitiesObject



213
# File 'lib/ankit/challenge.rb', line 213

def maturities; slots.map(&:maturity);  end

#nfailedObject



159
# File 'lib/ankit/challenge.rb', line 159

def nfailed; @slots.count { |c| c.rating == :failed }; end

#npassedObject



158
# File 'lib/ankit/challenge.rb', line 158

def npassed; @slots.count { |c| c.rating == :passed }; end

#over?Boolean

Returns:

  • (Boolean)


157
# File 'lib/ankit/challenge.rb', line 157

def over?; @slots.size <= @index; end

#passObject



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ankit/challenge.rb', line 179

def pass
  unless already_failed?
    last_slot = current_slot
    last_slot.rating = :passed
    last_slot.event = make_happen(PassCommand::EVENT_HAPPENING, to_card_name(current_path), this_round)
    session.passed_on(last_slot.event)
  end

  @index += 1
  self
end

#round_deltaObject



145
146
147
# File 'lib/ankit/challenge.rb', line 145

def round_delta
  latest_round - this_round
end

#runtimeObject



149
# File 'lib/ankit/challenge.rb', line 149

def runtime; @session.runtime; end

#sizeObject



156
# File 'lib/ankit/challenge.rb', line 156

def size; @slots.size; end

#styled_indicatorObject



202
203
204
205
206
207
208
209
210
211
# File 'lib/ankit/challenge.rb', line 202

def styled_indicator
  indicator.to_enum(:each_char).map do |i|
    case i
    when "x"; StylableText.styled_text(i, :failed)
    when "o"; StylableText.styled_text(i, :passed)
    when "-"; StylableText.styled_text(i, :pending)
    else; i
    end
  end.join
end