class SciolyFF::Interpreter::HTML::Helpers
Holds helper methods used in template.html.erb
Constants
- STATES_BY_POSTAL_CODE
Public Instance Methods
eval_with_binding(src, interpreter, hide_raw, color)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 10 def eval_with_binding(src, interpreter, hide_raw, color) i = interpreter css_file_content = File.read(File.join(__dir__, 'main.css')) js_file_content = File.read(File.join(__dir__, 'main.js')) eval(src) end
template()
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 6 def template File.read(File.join(__dir__, 'template.html.erb')) end
Private Instance Methods
abbr_school(school)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 148 def abbr_school(school) school.sub('Elementary School', 'Elementary') .sub('Elementary/Middle School', 'E.M.S.') .sub('Middle School', 'M.S.') .sub('Junior High School', 'J.H.S.') .sub(%r{Middle[ /-]High School}, 'M.H.S') .sub('Junior/Senior High School', 'Jr./Sr. H.S.') .sub('High School', 'H.S.') .sub('Secondary School', 'Secondary') end
acronymize(phrase)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 129 def acronymize(phrase) phrase.split(' ') .select { |w| /^[[:upper:]]/.match(w) } .map { |w| w[0] } .join end
bids_sup_tag(team)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 199 def bids_sup_tag(team) return '' unless team.earned_bid? "<sup>✧</sup>" end
bids_sup_tag_note(tournament)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 205 def bids_sup_tag_note(tournament) next_tournament = if tournament.level == 'Regionals' "#{tournament.state} State Tournament" else "National Tournament" end qualifiee = tournament.bids_per_school > 1 ? 'team' : 'school' "Qualified #{qualifiee} for the #{tournament.year} #{next_tournament}" end
expand_state_name(postal_code)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 136 def expand_state_name(postal_code) STATES_BY_POSTAL_CODE[postal_code.to_sym] end
format_school(team)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 140 def format_school(team) if team.school_abbreviation abbr_school(team.school_abbreviation) else abbr_school(team.school) end end
full_school_name(team)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 159 def full_school_name(team) location = if team.city then "(#{team.city}, #{team.state})" else "(#{team.state})" end [team.school, location].join(' ') end
full_team_name(team)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 166 def full_team_name(team) location = if team.city then "(#{team.city}, #{team.state})" else "(#{team.state})" end [team.school, team.suffix, location].join(' ') end
placing_notes(placing)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 215 def placing_notes(placing) place = placing.place points = placing.isolated_points [ ('trial event' if placing.event.trial?), ('trialed event' if placing.event.trialed?), ('disqualified' if placing.disqualified?), ('did not participate' if placing.did_not_participate?), ('participation points only' if placing.participation_only?), ('tie' if placing.tie?), ('exempt' if placing.exempt?), ('points limited' if placing.points_limited_by_maximum_place?), ('unknown place' if placing.unknown?), ('placed behind exhibition team'\ if placing.points_affected_by_exhibition? && place - points == 1), ('placed behind exhibition teams'\ if placing.points_affected_by_exhibition? && place - points > 1), ('dropped'\ if placing.dropped_as_part_of_worst_placings?) ].compact.join(', ').capitalize end
summary_titles()
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 180 def summary_titles %w[ Champion Runner-up Third-place Fourth-place Fifth-place Sixth-place ] end
sup_tag(placing)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 191 def sup_tag(placing) exempt = placing.exempt? || placing.dropped_as_part_of_worst_placings? tie = placing.tie? && !placing.points_limited_by_maximum_place? return '' unless tie || exempt "<sup>#{'◊' if exempt}#{'*' if tie}</sup>" end
team_attended?(team)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 173 def team_attended?(team) team .placings .map(&:participated?) .any? end
tournament_title(t_info)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 103 def tournament_title(t_info) return t_info.name if t_info.name case t_info.level when 'Nationals' 'Science Olympiad National Tournament' when 'States' "#{expand_state_name(t_info.state)} Science Olympiad State Tournament" when 'Regionals' "#{t_info.location} Regional Tournament" when 'Invitational' "#{t_info.location} Invitational" end end
tournament_title_short(t_info)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 118 def tournament_title_short(t_info) case t_info.level when 'Nationals' 'National Tournament' when 'States' "#{t_info.state} State Tournament" when 'Regionals', 'Invitational' t_info.short_name end end
trophy_and_medal_colors()
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 74 def trophy_and_medal_colors %w[ #ffee58 #cfd8dc #d8bf99 #ffefc0 #dcedc8 #f8bbd0 #eeccff #fdd5b4 #ebedd8 #d4f0f1 ] end
trophy_and_medal_css(trophies, medals)
click to toggle source
# File lib/sciolyff/interpreter/html/helpers.rb, line 89 def trophy_and_medal_css(trophies, medals) trophy_and_medal_colors.map.with_index do |color, i| [ ("td.event-points[data-points='#{i+1}'] div" if i < medals), ("td.event-points-focus[data-points='#{i+1}'] div" if i < medals), ("div#team-detail tr[data-points='#{i+1}']" if i < medals), ("td.rank[data-points='#{i+1}'] div" if i < trophies) ].compact.join(',') + "{background-color: #{color};border-radius: 1em;}" end.join + trophy_and_medal_colors.map.with_index do |color, i| "div#team-detail tr[data-points='#{i+1}'] td:first-child" if i < medals end.compact.join(',') + "{padding-left: 0.5em;}" end