sashite-ggn 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +523 -521
  3. data/VERSION.semver +1 -1
  4. data/lib/sashite/ggn.rb +3 -2
  5. data/lib/sashite/ggn/ability.rb +11 -19
  6. data/lib/sashite/ggn/actor.rb +5 -13
  7. data/lib/sashite/ggn/ally.rb +6 -14
  8. data/lib/sashite/ggn/area.rb +6 -14
  9. data/lib/sashite/ggn/attacked.rb +6 -14
  10. data/lib/sashite/ggn/boolean.rb +6 -14
  11. data/lib/sashite/ggn/digit.rb +6 -14
  12. data/lib/sashite/ggn/digit_excluding_zero.rb +6 -14
  13. data/lib/sashite/ggn/direction.rb +6 -14
  14. data/lib/sashite/ggn/gameplay.rb +8 -28
  15. data/lib/sashite/ggn/gameplay_into_base64.rb +7 -14
  16. data/lib/sashite/ggn/integer.rb +6 -14
  17. data/lib/sashite/ggn/last_moved_actor.rb +6 -14
  18. data/lib/sashite/ggn/maximum_magnitude.rb +6 -14
  19. data/lib/sashite/ggn/name.rb +6 -14
  20. data/lib/sashite/ggn/negative_integer.rb +6 -14
  21. data/lib/sashite/ggn/null.rb +7 -9
  22. data/lib/sashite/ggn/object.rb +11 -19
  23. data/lib/sashite/ggn/occupied.rb +12 -20
  24. data/lib/sashite/ggn/pattern.rb +7 -16
  25. data/lib/sashite/ggn/previous_moves_counter.rb +6 -14
  26. data/lib/sashite/ggn/promotable_into_actors.rb +8 -17
  27. data/lib/sashite/ggn/required.rb +6 -14
  28. data/lib/sashite/ggn/self.rb +7 -9
  29. data/lib/sashite/ggn/square.rb +11 -19
  30. data/lib/sashite/ggn/state.rb +9 -17
  31. data/lib/sashite/ggn/subject.rb +11 -19
  32. data/lib/sashite/ggn/unsigned_integer.rb +6 -14
  33. data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +5 -13
  34. data/lib/sashite/ggn/verb.rb +15 -24
  35. data/lib/sashite/ggn/zero.rb +7 -9
  36. data/sashite-ggn.gemspec +2 -4
  37. data/test/test_ggn.rb +501 -495
  38. data/test/test_ggn_ability.rb +10 -10
  39. data/test/test_ggn_actor.rb +516 -536
  40. data/test/test_ggn_ally.rb +13 -29
  41. data/test/test_ggn_area.rb +9 -67
  42. data/test/test_ggn_attacked.rb +13 -29
  43. data/test/test_ggn_boolean.rb +10 -26
  44. data/test/test_ggn_digit.rb +10 -10
  45. data/test/test_ggn_digit_excluding_zero.rb +10 -11
  46. data/test/test_ggn_direction.rb +10 -10
  47. data/test/test_ggn_gameplay.rb +22 -38
  48. data/test/test_ggn_gameplay_into_base64.rb +511 -501
  49. data/test/test_ggn_integer.rb +19 -21
  50. data/test/test_ggn_last_moved_actor.rb +13 -29
  51. data/test/test_ggn_maximum_magnitude.rb +18 -16
  52. data/test/test_ggn_name.rb +9 -39
  53. data/test/test_ggn_negative_integer.rb +10 -10
  54. data/test/test_ggn_null.rb +10 -10
  55. data/test/test_ggn_object.rb +22 -24
  56. data/test/test_ggn_occupied.rb +40 -64
  57. data/test/test_ggn_pattern.rb +12 -10
  58. data/test/test_ggn_previous_moves_counter.rb +18 -20
  59. data/test/test_ggn_promotable_into_actors.rb +529 -549
  60. data/test/test_ggn_required.rb +10 -26
  61. data/test/test_ggn_self.rb +10 -10
  62. data/test/test_ggn_square.rb +14 -16
  63. data/test/test_ggn_state.rb +15 -19
  64. data/test/test_ggn_subject.rb +17 -19
  65. data/test/test_ggn_unsigned_integer.rb +30 -12
  66. data/test/test_ggn_unsigned_integer_excluding_zero.rb +14 -10
  67. data/test/test_ggn_verb.rb +16 -15
  68. data/test/test_ggn_zero.rb +10 -10
  69. metadata +4 -18
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/lib/sashite/ggn.rb CHANGED
@@ -2,8 +2,9 @@ require_relative 'ggn/gameplay'
2
2
 
3
3
  module Sashite
4
4
  module GGN
5
- def self.load str
6
- Gameplay.new str
5
+ # Loads a document from the current io stream.
6
+ def self.load io
7
+ Gameplay.load io
7
8
  end
8
9
  end
9
10
  end
@@ -4,34 +4,26 @@ require_relative 'object'
4
4
 
5
5
  module Sashite
6
6
  module GGN
7
- class Ability
7
+ module Ability
8
8
  PATTERN = /#{Subject::PATTERN}\^#{Verb::PATTERN}=#{Object::PATTERN}/
9
9
 
10
- def self.valid? str
11
- !!str.match("^#{PATTERN}$")
10
+ def self.valid? io
11
+ !!io.match("^#{PATTERN}$")
12
12
  end
13
13
 
14
- attr_reader :subject, :verb, :object
14
+ def self.load io
15
+ raise ArgumentError unless valid? io
15
16
 
16
- def initialize str
17
- raise ArgumentError unless self.class.valid? str
17
+ subject = Subject.load io.split('^').fetch 0
18
+ verb = Verb.load io.split('^').fetch(1).split('=').fetch 0
19
+ object = Object.load io.split('=').fetch 1
18
20
 
19
- @subject = Subject.new str.split('^').fetch 0
20
- @verb = Verb.new str.split('^').fetch(1).split('=').fetch 0
21
- @object = Object.new str.split('=').fetch 1
22
- end
23
-
24
- def as_json
25
21
  {
26
- subject: @subject.as_json,
27
- verb: @verb.as_json,
28
- object: @object.as_json
22
+ subject: subject,
23
+ verb: verb,
24
+ object: object
29
25
  }
30
26
  end
31
-
32
- def to_s
33
- "#{@subject}^#{@verb}=#{@object}"
34
- end
35
27
  end
36
28
  end
37
29
  end
@@ -6,22 +6,14 @@ module Sashite
6
6
  class Actor
7
7
  PATTERN = /(#{Self::PATTERN}|#{GameplayIntoBase64::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (Self.valid?(str) ? Self.instance : GameplayIntoBase64.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ Self.valid?(io) ? Self.load : GameplayIntoBase64.load(io)
25
17
  end
26
18
  end
27
19
  end
@@ -3,25 +3,17 @@ require_relative 'null'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class Ally
6
+ module Ally
7
7
  PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (Null.valid?(str) ? Null.instance : Boolean.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ Null.valid?(io) ? Null.load : Boolean.load(io)
25
17
  end
26
18
  end
27
19
  end
@@ -1,24 +1,16 @@
1
1
  module Sashite
2
2
  module GGN
3
- class Area
3
+ module Area
4
4
  PATTERN = /(all|furthest_rank|palace|furthest_one-third|nearest_two-thirds)/
5
5
 
6
- def self.valid? str
7
- !!str.match("^#{PATTERN}$")
6
+ def self.valid? io
7
+ !!io.match("^#{PATTERN}$")
8
8
  end
9
9
 
10
- def initialize str
11
- raise ArgumentError unless self.class.valid? str
10
+ def self.load io
11
+ raise ArgumentError unless valid? io
12
12
 
13
- @value = str.to_sym
14
- end
15
-
16
- def as_json
17
- @value
18
- end
19
-
20
- def to_s
21
- @value.to_s
13
+ io.to_sym
22
14
  end
23
15
  end
24
16
  end
@@ -3,25 +3,17 @@ require_relative 'null'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class Attacked
6
+ module Attacked
7
7
  PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (Null.valid?(str) ? Null.instance : Boolean.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ Null.valid?(io) ? Null.load : Boolean.load(io)
25
17
  end
26
18
  end
27
19
  end
@@ -1,24 +1,16 @@
1
1
  module Sashite
2
2
  module GGN
3
- class Boolean
3
+ module Boolean
4
4
  PATTERN = /[ft]/
5
5
 
6
- def self.valid? str
7
- !!str.match("^#{PATTERN}$")
6
+ def self.valid? io
7
+ !!io.match("^#{PATTERN}$")
8
8
  end
9
9
 
10
- def initialize str
11
- raise ArgumentError unless self.class.valid? str
10
+ def self.load io
11
+ raise ArgumentError unless valid? io
12
12
 
13
- @value = str.to_sym
14
- end
15
-
16
- def as_json
17
- @value == :t
18
- end
19
-
20
- def to_s
21
- @value.to_s
13
+ io.to_sym == :t
22
14
  end
23
15
  end
24
16
  end
@@ -3,25 +3,17 @@ require_relative 'zero'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class Digit
6
+ module Digit
7
7
  PATTERN = /(#{Zero::PATTERN}|#{DigitExcludingZero::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (Zero.valid?(str) ? Zero.instance : DigitExcludingZero.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ Zero.valid?(io) ? Zero.load : DigitExcludingZero.load(io)
25
17
  end
26
18
  end
27
19
  end
@@ -1,24 +1,16 @@
1
1
  module Sashite
2
2
  module GGN
3
- class DigitExcludingZero
3
+ module DigitExcludingZero
4
4
  PATTERN = /[1-9]/
5
5
 
6
- def self.valid? str
7
- !!str.match("^#{PATTERN}$")
6
+ def self.valid? io
7
+ !!io.match("^#{PATTERN}$")
8
8
  end
9
9
 
10
- def initialize str
11
- raise ArgumentError unless self.class.valid? str
10
+ def self.load io
11
+ raise ArgumentError unless valid? io
12
12
 
13
- @value = str.to_i
14
- end
15
-
16
- def as_json
17
- @value
18
- end
19
-
20
- def to_s
21
- @value.to_s
13
+ io.to_i
22
14
  end
23
15
  end
24
16
  end
@@ -2,25 +2,17 @@ require_relative 'integer'
2
2
 
3
3
  module Sashite
4
4
  module GGN
5
- class Direction
5
+ module Direction
6
6
  PATTERN = /(#{Integer::PATTERN},)*#{Integer::PATTERN}/
7
7
 
8
- def self.valid? str
9
- !!str.match("^#{PATTERN}$")
8
+ def self.valid? io
9
+ !!io.match("^#{PATTERN}$")
10
10
  end
11
11
 
12
- def initialize str
13
- raise ArgumentError unless self.class.valid? str
12
+ def self.load io
13
+ raise ArgumentError unless valid? io
14
14
 
15
- @integers = str.split(',').map { |i| Integer.new(i) }
16
- end
17
-
18
- def as_json
19
- @integers.map &:as_json
20
- end
21
-
22
- def to_s
23
- @integers.join ','
15
+ io.split(',').map { |s| Integer.load s }
24
16
  end
25
17
  end
26
18
  end
@@ -1,39 +1,19 @@
1
- require 'sashite-cgh'
2
1
  require_relative 'pattern'
3
2
 
4
3
  module Sashite
5
4
  module GGN
6
- class Gameplay
5
+ module Gameplay
7
6
  PATTERN = /#{Pattern::PATTERN}(\. #{Pattern::PATTERN})*\./
8
7
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$") && str.split('. ').sort.join('. ') == str
8
+ def self.valid? io
9
+ io.match("^#{PATTERN}$") &&
10
+ io.split('. ').sort.join('. ') == io &&
11
+ io[0..-2].split('. ').uniq.join('. ').concat('.') == io
11
12
  end
12
13
 
13
- attr_reader :patterns
14
-
15
- def initialize str
16
- raise ArgumentError unless self.class.valid? str
17
-
18
- @patterns = str[0..-2].split('. ').map { |pattern| Pattern.new pattern }
19
- end
20
-
21
- def as_json
22
- @patterns.map &:as_json
23
- end
24
-
25
- def to_s
26
- @patterns.map(&:to_s).join('. ') + '.'
27
- end
28
-
29
- def to_cgh
30
- Sashite::CGH.parse to_s
31
- end
32
-
33
- def dimensions
34
- first_pattern = @patterns.fetch 0
35
- first_ability = first_pattern.abilities.fetch 0
36
- first_ability.verb.dimensions
14
+ def self.load io
15
+ raise ArgumentError unless valid? io
16
+ io[0..-2].split('. ').map { |s| Pattern.load s }
37
17
  end
38
18
  end
39
19
  end
@@ -3,25 +3,18 @@ require_relative 'gameplay'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class GameplayIntoBase64
6
+ module GameplayIntoBase64
7
7
  PATTERN = /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$") && Gameplay.valid?(Base64.strict_decode64(str))
9
+ def self.valid? io
10
+ io.match("^#{PATTERN}$") &&
11
+ Gameplay.valid?(Base64.strict_decode64(io))
11
12
  end
12
13
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
14
+ def self.load io
15
+ raise ArgumentError unless valid? io
15
16
 
16
- @value = Gameplay.new Base64.strict_decode64(str)
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- Base64.strict_encode64 @value.to_s
17
+ Gameplay.load Base64.strict_decode64(io)
25
18
  end
26
19
  end
27
20
  end
@@ -3,25 +3,17 @@ require_relative 'unsigned_integer'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class Integer
6
+ module Integer
7
7
  PATTERN = /(#{NegativeInteger::PATTERN}|#{UnsignedInteger::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (NegativeInteger.valid?(str) ? NegativeInteger.new(str) : UnsignedInteger.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ NegativeInteger.valid?(io) ? NegativeInteger.load(io) : UnsignedInteger.load(io)
25
17
  end
26
18
  end
27
19
  end
@@ -3,25 +3,17 @@ require_relative 'null'
3
3
 
4
4
  module Sashite
5
5
  module GGN
6
- class LastMovedActor
6
+ module LastMovedActor
7
7
  PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
8
 
9
- def self.valid? str
10
- !!str.match("^#{PATTERN}$")
9
+ def self.valid? io
10
+ !!io.match("^#{PATTERN}$")
11
11
  end
12
12
 
13
- def initialize str
14
- raise ArgumentError unless self.class.valid? str
13
+ def self.load io
14
+ raise ArgumentError unless valid? io
15
15
 
16
- @value = (Null.valid?(str) ? Null.instance : Boolean.new(str))
17
- end
18
-
19
- def as_json
20
- @value.as_json
21
- end
22
-
23
- def to_s
24
- @value.to_s
16
+ Null.valid?(io) ? Null.load : Boolean.load(io)
25
17
  end
26
18
  end
27
19
  end