Class: Opening

Inherits:
Object
  • Object
show all
Defined in:
lib/eco_classifier/opening.rb

Overview

Represents an opening as parsed from scid.eco

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  self.eco   = options[:eco]
  self.name  = options[:name]
  self.pgn   = options[:pgn]
end

Instance Attribute Details

#ecoObject

Returns the value of attribute eco.



5
6
7
# File 'lib/eco_classifier/opening.rb', line 5

def eco
  @eco
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/eco_classifier/opening.rb', line 5

def name
  @name
end

#pgnObject

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(options = {})
  {
    eco: base_eco,
    name: base_name,
    variation: variation,
    full_name: self.name
  }
end

#base_ecoObject



13
14
15
# File 'lib/eco_classifier/opening.rb', line 13

def base_eco
  self.eco[/\A([A-E]\d{2})/, 1]
end

#base_nameObject



17
18
19
# File 'lib/eco_classifier/opening.rb', line 17

def base_name
  self.name.split(":").first
end

#move_listObject



42
43
44
# File 'lib/eco_classifier/opening.rb', line 42

def move_list
  pgn.gsub(/\d+\./, '').gsub(/\*/, '').strip.split(/\s+/)
end

#variationObject



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_lineObject



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_nameObject



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