brainfuck_converter 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brainfuck_converter.rb +10 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43df11e483a96f0a38b849a4bcb1af18707246932373b88aa213d1ff665adaa7
4
- data.tar.gz: 27c6d1055223d616a9c23de677e9815254b1df869a827e9231713faa08cb2c33
3
+ metadata.gz: d76749a2b9454523f96778446fdcac3747c5d7564cc1f54fefbb9fbca1e0b73f
4
+ data.tar.gz: 7f808e7e6bb8f830c3625d44ab2a144774f364482baa7c534946f146c6ff930d
5
5
  SHA512:
6
- metadata.gz: c47111e9e6954e8c6818411e0cd5f3d67b0ce1552033f39eebe7a474342d1aef6708b96000bb97ae03a8c4f1351cb94e2c7fa63597f7cad6499da7245ae5d19e
7
- data.tar.gz: c78ac2adf3b2d790d1423580d442e35d17360ff39de92519b0be95ce2c95d090e6b28f5203933ff6a71782ea1d880fc7158e2cbe33a3ecfd42619d768a4b076b
6
+ metadata.gz: 0d4a7f1baafbd5814200cd96c65f61df5333631e5715cb079fa9dc39ad5e40482daf5bd83fb07670b641e670836e20128681d5cf0024a2a09c3841319ba240bc
7
+ data.tar.gz: f905a90495eea5caee6deb917e7ad7ab64997e675b8cd36f33ebaa8a974cee5c92fb2bb1c9063d87bb92c053bdd82396be9c2087e6c9842521cd86e136c2fb1c
@@ -11,6 +11,8 @@ class BrainfuckConverter
11
11
  loop_end: ']'
12
12
  }.freeze
13
13
 
14
+ ASCII_MAX = 127
15
+
14
16
  attr_reader :code
15
17
  attr_accessor :cmds
16
18
 
@@ -35,24 +37,27 @@ class BrainfuckConverter
35
37
  # con = BrainfuckConverter.new
36
38
  #
37
39
  # con.convert 'Hello World!' # => 'Hello World!'
38
- # con.code # => '++++++++++++++[>+>++>+++>++++>+++++>++++++>++++++... too long'
40
+ # con.code # => "++++++++++++++[>+>++>+++>++++>+++++>++++++>++++++... too long"
39
41
  #
40
42
  # con.convert 'Hallo Welt!', 15 # => 'Hallo Welt!'
41
- # con.code # => '+++++++[>+>++>+++>++++>+++++>++++++>+++++++>+++++... too long'
43
+ # con.code # => "+++++++[>+>++>+++>++++>+++++>++++++>+++++++>+++++... too long"
42
44
  def convert(text, cells_num = 8)
43
- # To output a string in Brainfuck, 'auxiliary numbers' are written into
45
+ # To output a string in Brainfuck, "auxiliary numbers" are written into
44
46
  # certain cells. If a letter is to be output, the letter is converted into
45
47
  # an ASCII value and the auxiliary number that is closest to it is searched for.
46
48
  # This is then adjusted so that it corresponds to the ASCII value of the letter.
47
49
  # The auxiliary number or the letter is then output.
48
50
 
49
- return false if cells_num < 1
51
+ raise ArgumentError, 'Text must be a string' unless text.is_a? String
52
+ raise ArgumentError, 'Number of cells must be a integer' unless cells_num.is_a? Integer
53
+ raise ArgumentError, 'Number of cells must be larger than 0' if cells_num < 1
54
+ raise ArgumentError, "Number of cells must be smaller than #{ASCII_MAX}" if cells_num > ASCII_MAX
50
55
 
51
56
  # Code is cleared. A new Brainfuck program is started.
52
57
  @code = ''
53
58
 
54
59
  # Calculating the auxiliary numbers
55
- space_cells = 127 / (cells_num + 1)
60
+ space_cells = ASCII_MAX / (cells_num + 1)
56
61
  @cell_values = []
57
62
  @cell_values[0] = space_cells
58
63
  for i in 1...cells_num
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainfuck_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-27 00:00:00.000000000 Z
12
+ date: 2023-04-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Gem, which makes it possible to convert any ASCII characters into brainfuck
15
15
  code