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.



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

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.



135
136
137
# File 'lib/ankit/challenge.rb', line 135

def index
  @index
end

#sessionObject (readonly)

Returns the value of attribute session.



135
136
137
# File 'lib/ankit/challenge.rb', line 135

def session
  @session
end

#slotsObject (readonly)

Returns the value of attribute slots.



135
136
137
# File 'lib/ankit/challenge.rb', line 135

def slots
  @slots
end

#this_roundObject (readonly)

Returns the value of attribute this_round.



135
136
137
# File 'lib/ankit/challenge.rb', line 135

def this_round
  @this_round
end

Instance Method Details

#already_failed?Boolean

Returns:

  • (Boolean)


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

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

#attackObject



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

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

#current_cardObject



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

def current_card; card_at(current_path); end

#current_pathObject



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

def current_path; current_slot.path; end

#current_slotObject



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

def current_slot; @slots[@index]; end

#failObject



165
166
167
168
169
170
171
172
173
174
# File 'lib/ankit/challenge.rb', line 165

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



188
189
190
191
192
193
194
195
196
197
# File 'lib/ankit/challenge.rb', line 188

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



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

def last_card; card_at(last_path); end

#last_pathObject



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

def last_path; last_slot.path; end

#last_slotObject



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

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

#maturitiesObject



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

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

#nfailedObject



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

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

#npassedObject



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

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

#over?Boolean

Returns:

  • (Boolean)


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

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

#passObject



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ankit/challenge.rb', line 176

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



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

def round_delta
  latest_round - this_round
end

#runtimeObject



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

def runtime; @session.runtime; end

#sizeObject



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

def size; @slots.size; end

#styled_indicatorObject



199
200
201
202
203
204
205
206
207
208
# File 'lib/ankit/challenge.rb', line 199

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