brainfuck_converter 1.1.1 → 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 +9 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826d980c5b711943c207a5fe68a7e3f3df8f224151673b563cab4cc876793dbf
4
- data.tar.gz: 0f39cab2d49c76ec7f60cbc0eb23edb2daeeece9aa23dc80511bccba95bd6b2f
3
+ metadata.gz: d76749a2b9454523f96778446fdcac3747c5d7564cc1f54fefbb9fbca1e0b73f
4
+ data.tar.gz: 7f808e7e6bb8f830c3625d44ab2a144774f364482baa7c534946f146c6ff930d
5
5
  SHA512:
6
- metadata.gz: fedc5430e6289ef9a3c2d687f26a524c3e0b857adfa2976b449a589b6341b1ea110f488cbe12b56301340591e8d98540e7b8de32c536c7512d58c50688b74b08
7
- data.tar.gz: cefc521ff6f60914354e3a98e687080f5dc353898d87c744df95224bdeb75bb06e2ee2fe596b4e968477a6331acc9e5267ade92ad628fc342ee0a1f3f78bbc9a
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,10 +37,10 @@ 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
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
@@ -46,13 +48,16 @@ class BrainfuckConverter
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.1
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