Class: PGN::MoveText

Inherits:
Object
  • Object
show all
Defined in:
lib/pgn/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notation, annotation = nil, comment = nil, variations = []) ⇒ MoveText

Returns a new instance of MoveText.



9
10
11
12
13
14
# File 'lib/pgn/game.rb', line 9

def initialize(notation, annotation = nil, comment = nil, variations = [])
  @notation = notation
  @annotation = annotation
  @comment = clean_text(comment)
  @variations = variations
end

Instance Attribute Details

#annotationObject

Returns the value of attribute annotation.



7
8
9
# File 'lib/pgn/game.rb', line 7

def annotation
  @annotation
end

#commentObject

Returns the value of attribute comment.



7
8
9
# File 'lib/pgn/game.rb', line 7

def comment
  @comment
end

#notationObject

Returns the value of attribute notation.



7
8
9
# File 'lib/pgn/game.rb', line 7

def notation
  @notation
end

#variationsObject

Returns the value of attribute variations.



7
8
9
# File 'lib/pgn/game.rb', line 7

def variations
  @variations
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/pgn/game.rb', line 16

def ==(other)
  to_s == other.to_s
end

#clean_text(text) ⇒ Object



32
33
34
# File 'lib/pgn/game.rb', line 32

def clean_text(text)
  text&.gsub(/{(.*)}/, '\1')&.gsub(/\s+/, ' ')&.strip
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pgn/game.rb', line 20

def eql?(other)
  self == other
end

#hashObject



24
25
26
# File 'lib/pgn/game.rb', line 24

def hash
  @notation.hash
end

#to_sObject



28
29
30
# File 'lib/pgn/game.rb', line 28

def to_s
  @notation
end