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.



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

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.



5
6
7
# File 'lib/pgn/game.rb', line 5

def annotation
  @annotation
end

#commentObject

Returns the value of attribute comment.



5
6
7
# File 'lib/pgn/game.rb', line 5

def comment
  @comment
end

#notationObject

Returns the value of attribute notation.



5
6
7
# File 'lib/pgn/game.rb', line 5

def notation
  @notation
end

#variationsObject

Returns the value of attribute variations.



5
6
7
# File 'lib/pgn/game.rb', line 5

def variations
  @variations
end

Instance Method Details

#==(m) ⇒ Object



14
15
16
# File 'lib/pgn/game.rb', line 14

def ==(m)
  to_s == m.to_s
end

#clean_text(text) ⇒ Object



30
31
32
# File 'lib/pgn/game.rb', line 30

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

#eql?(m) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pgn/game.rb', line 18

def eql?(m)
  self == m
end

#hashObject



22
23
24
# File 'lib/pgn/game.rb', line 22

def hash
  @notation.hash
end

#to_sObject



26
27
28
# File 'lib/pgn/game.rb', line 26

def to_s
  @notation
end