Class: BracketTree::Template::Base
- Inherits:
-
Object
- Object
- BracketTree::Template::Base
- Defined in:
- lib/bracket_tree/template.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#seats ⇒ Object
Returns the value of attribute seats.
-
#starting_seats ⇒ Object
(also: #seed_order)
Returns the value of attribute starting_seats.
Class Method Summary collapse
-
.by_size(size) ⇒ Object
Reads stored JSON files to generate a Template.
-
.from_json(json) ⇒ BracketTree::Template
Generates Template from JSON.
-
.location ⇒ String
Folder location of the template JSON files.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#to_h ⇒ Hash
Returns hash representation of the Template.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
50 51 52 53 54 |
# File 'lib/bracket_tree/template.rb', line 50 def initialize @seats = [] @starting_seats = [] @matches = [] end |
Instance Attribute Details
#matches ⇒ Object
Returns the value of attribute matches.
48 49 50 |
# File 'lib/bracket_tree/template.rb', line 48 def matches @matches end |
#seats ⇒ Object
Returns the value of attribute seats.
48 49 50 |
# File 'lib/bracket_tree/template.rb', line 48 def seats @seats end |
#starting_seats ⇒ Object Also known as: seed_order
Returns the value of attribute starting_seats.
48 49 50 |
# File 'lib/bracket_tree/template.rb', line 48 def starting_seats @starting_seats end |
Class Method Details
.by_size(size) ⇒ Object
Reads stored JSON files to generate a Template
return [nil, BracketTree::Template] template - the resulting bracket template
10 11 12 13 14 15 16 17 18 |
# File 'lib/bracket_tree/template.rb', line 10 def by_size size filename = File.join location, "#{size}.json" if File.exists? filename from_json JSON.parse(File.read(filename), symbolize_names: true) else return nil end end |
.from_json(json) ⇒ BracketTree::Template
Generates Template from JSON
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bracket_tree/template.rb', line 24 def from_json json template = new if json[:seats] template.seats = json[:seats].map { |s| s[:position] } end if json[:starting_seats] template.starting_seats = json[:starting_seats] end if json[:matches] template.matches = json[:matches] end template end |
.location ⇒ String
Folder location of the template JSON files. Abstract method
43 44 45 |
# File 'lib/bracket_tree/template.rb', line 43 def location raise NotImplementedError, 'Abstract method, please define `location` in subclass.' end |
Instance Method Details
#to_h ⇒ Hash
Returns hash representation of the Template
59 60 61 62 63 64 65 |
# File 'lib/bracket_tree/template.rb', line 59 def to_h { seats: @seats.map { |s| { position: s } }, starting_seats: @starting_seats, matches: @matches } end |