Class: Opening
- Inherits:
-
Object
- Object
- Opening
- Defined in:
- lib/eco_classifier/opening.rb
Overview
Represents an opening as parsed from scid.eco
Instance Attribute Summary collapse
-
#eco ⇒ Object
Returns the value of attribute eco.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pgn ⇒ Object
Returns the value of attribute pgn.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #base_eco ⇒ Object
- #base_name ⇒ Object
-
#initialize(options) ⇒ Opening
constructor
A new instance of Opening.
- #move_list ⇒ Object
- #variation ⇒ Object
- #variation_line ⇒ Object
- #variation_name ⇒ Object
Constructor Details
#initialize(options) ⇒ Opening
Returns a new instance of Opening.
7 8 9 10 11 |
# File 'lib/eco_classifier/opening.rb', line 7 def initialize() self.eco = [:eco] self.name = [:name] self.pgn = [:pgn] end |
Instance Attribute Details
#eco ⇒ Object
Returns the value of attribute eco.
5 6 7 |
# File 'lib/eco_classifier/opening.rb', line 5 def eco @eco end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/eco_classifier/opening.rb', line 5 def name @name end |
#pgn ⇒ Object
Returns the value of attribute pgn.
5 6 7 |
# File 'lib/eco_classifier/opening.rb', line 5 def pgn @pgn end |
Instance Method Details
#as_json(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/eco_classifier/opening.rb', line 46 def as_json( = {}) { eco: base_eco, name: base_name, variation: variation, full_name: self.name } end |
#base_eco ⇒ Object
13 14 15 |
# File 'lib/eco_classifier/opening.rb', line 13 def base_eco self.eco[/\A([A-E]\d{2})/, 1] end |
#base_name ⇒ Object
17 18 19 |
# File 'lib/eco_classifier/opening.rb', line 17 def base_name self.name.split(":").first end |
#move_list ⇒ Object
42 43 44 |
# File 'lib/eco_classifier/opening.rb', line 42 def move_list pgn.gsub(/\d+\./, '').gsub(/\*/, '').strip.split(/\s+/) end |
#variation ⇒ Object
21 22 23 24 25 26 |
# File 'lib/eco_classifier/opening.rb', line 21 def variation return @variation if defined?(@variation) match = self.name[/:(.*)/, 1] return unless match @variation = match.strip end |
#variation_line ⇒ Object
35 36 37 38 39 40 |
# File 'lib/eco_classifier/opening.rb', line 35 def variation_line return unless variation return @variation_line if defined?(@variation_line) @variation_line = variation.split(",").map(&:strip).select {|str| str[0] =~ /\d/ }.join(", ") end |
#variation_name ⇒ Object
28 29 30 31 32 33 |
# File 'lib/eco_classifier/opening.rb', line 28 def variation_name return unless variation return @variation_name if defined?(@variation_name) @variation_name = variation.split(",").map(&:strip).select {|str| str[0] !~ /\d/ }.join(", ") end |