Class: SciolyFF::Interpreter

Inherits:
Object
  • Object
show all
Includes:
HTML, Subdivisions, Tiebreaks
Defined in:
lib/sciolyff/interpreter.rb

Overview

Interprets the YAML representation of a SciolyFF file through objects that respond to idiomatic Ruby method calls

Defined Under Namespace

Modules: Bids, HTML, Subdivisions, Tiebreaks Classes: Event, Model, Penalty, Placing, Team, Tournament

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTML

#to_html, #to_json, #to_yaml

Constructor Details

#initialize(rep) ⇒ Interpreter

Returns a new instance of Interpreter.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sciolyff/interpreter.rb', line 19

def initialize(rep)
  if rep.instance_of? String
    rep = Psych.safe_load(rep,
                          permitted_classes: [Date],
                          symbolize_names: true)
  end
  create_models(@rep = rep)
  link_models(self)

  sort_events_naturally
  sort_teams_by_rank
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



17
18
19
# File 'lib/sciolyff/interpreter.rb', line 17

def events
  @events
end

#penaltiesObject (readonly)

Returns the value of attribute penalties.



17
18
19
# File 'lib/sciolyff/interpreter.rb', line 17

def penalties
  @penalties
end

#placingsObject (readonly)

Returns the value of attribute placings.



17
18
19
# File 'lib/sciolyff/interpreter.rb', line 17

def placings
  @placings
end

#teamsObject (readonly)

Returns the value of attribute teams.



17
18
19
# File 'lib/sciolyff/interpreter.rb', line 17

def teams
  @teams
end

#tournamentObject (readonly)

Returns the value of attribute tournament.



17
18
19
# File 'lib/sciolyff/interpreter.rb', line 17

def tournament
  @tournament
end

Instance Method Details

#subdivisionsObject



32
33
34
35
36
37
38
39
# File 'lib/sciolyff/interpreter.rb', line 32

def subdivisions
  @subdivisions ||=
    teams.map(&:subdivision)
         .uniq
         .compact
         .map { |sub| [sub, Interpreter.new(subdivision_rep(sub))] }
         .to_h
end