orenono 0.0.3 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e48e6407a724809d4b8bd117d6eb8fc06e9bfa3
4
- data.tar.gz: 3ce7a6805ff09af7476a0cf48c141ba5902b3c97
3
+ metadata.gz: 738786a3a96cb7467591f48251ab94546f7e36aa
4
+ data.tar.gz: 8c10f6afe9b82519971c907465db4b893730e99a
5
5
  SHA512:
6
- metadata.gz: 6055105683308a517c76163f4f01503bd510693b88ee9bd878ecd6234102086699ed2d2b1ca48bd6c1e3aac93b92a131853c4853ba1c43c2052b08a5678f2ff9
7
- data.tar.gz: 02634f14588ea542781fc25773e97bdec67f311ddd3a94f639ce11e535dbc39c0c22192711ca5a9aea30126a02821925d738c89e1bfdfb7dc10182705972b338
6
+ metadata.gz: 62050e69055938347175cd12a2c272ac03771e7f5f9acee0e16aa7cb7e5724c5ed1117ae16668f1fb2ec672f6db994e018c96e778e7331e7d756f8a36a686763
7
+ data.tar.gz: 21f6e72b2cce2642fdeab4b42c0bf69b3eb9e265320ca094efdec1c2fc29a9f970f7e72af9c1fdcd840e1ad5581b60dbc7b2cd117f1284b8717abe1b29c2e15a
@@ -0,0 +1,22 @@
1
+ ## v.0.1.3
2
+ 2015/05/05
3
+
4
+ ### New Features
5
+ * Support multibyte in generator.
6
+
7
+ ## v.0.0.3
8
+ 2014/09/11
9
+
10
+ ### New Features
11
+ * Support Brainf*ck code generator from ASCII code text.
12
+
13
+ ## v.0.0.2
14
+ 2014/09/10
15
+
16
+ ### New Features
17
+ * Support brainf*ck to your syntax converter.
18
+
19
+ ## v.0.0.1
20
+ 2014/08/31
21
+
22
+ * first release
data/README.md CHANGED
@@ -269,7 +269,7 @@ Hello, world!
269
269
 
270
270
  ## Contributing
271
271
 
272
- 1. Fork it ( https://github.com/[my-github-username]/orenono/fork )
272
+ 1. Fork it ( https://github.com/tbpgr/orenono/fork )
273
273
  2. Create your feature branch (`git checkout -b my-new-feature`)
274
274
  3. Commit your changes (`git commit -am 'Add some feature'`)
275
275
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,77 +1,78 @@
1
- # encoding: utf-8
2
- require 'orenono_dsl'
3
- require 'orenono_dsl_model'
4
-
5
- # rubocop:disable LineLength
6
- module Orenono
7
- # Brainf*ck code generator
8
- class Generator
9
- attr_reader :tables, :init_codes, :pointer, :config
10
-
11
- def self.generate(text, config)
12
- bf = new(text[0], config)
13
- text.split('').map(&:ord).each_with_object([bf.init_codes]) do |char, codes|
14
- codes << bf.diff(char)
15
- codes << bf.output
16
- end.join
17
- end
18
-
19
- def initialize(char, config)
20
- char_code = char.ord
21
- repeat = char_code / 10
22
- rest = char_code % 10
23
- @tables = []
24
- @pointer = 0
25
- @config = config
26
- @init_codes = ten_increment(config) +
27
- config.start_loop +
28
- config.next_cursol +
29
- increment(repeat) +
30
- config.previous_cursol +
31
- config.decrement +
32
- config.end_loop +
33
- config.next_cursol +
34
- increment(rest)
35
- @tables[@pointer] = char_code
36
- end
37
-
38
- def increment(count = 1)
39
- @tables[@pointer] = 0 unless @tables[@pointer]
40
- @tables[@pointer] += count
41
- @config.increment * count
42
- end
43
-
44
- def decrement(count = 1)
45
- @tables[@pointer] -= count
46
- @config.decrement * count
47
- end
48
-
49
- def diff(char_code)
50
- diff_of_code = char_code - @tables[@pointer]
51
- return '' if diff_of_code.zero?
52
- @tables[@pointer] += diff_of_code
53
- diff_of_code > 0 ? (@config.increment * diff_of_code) : (@config.decrement * diff_of_code.abs)
54
- end
55
-
56
- def next_pointer(count = 1)
57
- @pointer += count
58
- @config.next_cursol * count
59
- end
60
-
61
- def previous_pointer(count = 1)
62
- @pointer -= count
63
- @config.previous_cursol * count
64
- end
65
-
66
- def output(count = 1)
67
- @config.display * count
68
- end
69
-
70
- private
71
-
72
- def ten_increment(config)
73
- config.increment * 10
74
- end
75
- end
76
- end
77
- # rubocop:enable LineLength
1
+ # encoding: utf-8
2
+ require 'orenono_dsl'
3
+ require 'orenono_dsl_model'
4
+
5
+ # rubocop:disable LineLength
6
+ module Orenono
7
+ # Brainf*ck code generator
8
+ class Generator
9
+ attr_reader :tables, :init_codes, :pointer, :config
10
+
11
+ def self.generate(text, config)
12
+ bytes = text.bytes.to_a
13
+ bf = new(bytes[0], config)
14
+ bytes.each_with_object([bf.init_codes]) do |char, codes|
15
+ codes << bf.diff(char)
16
+ codes << bf.output
17
+ end.join
18
+ end
19
+
20
+ def initialize(char, config)
21
+ char_code = char
22
+ repeat = char_code / 10
23
+ rest = char_code % 10
24
+ @tables = []
25
+ @pointer = 0
26
+ @config = config
27
+ @init_codes = ten_increment(config) +
28
+ config.start_loop +
29
+ config.next_cursol +
30
+ increment(repeat) +
31
+ config.previous_cursol +
32
+ config.decrement +
33
+ config.end_loop +
34
+ config.next_cursol +
35
+ increment(rest)
36
+ @tables[@pointer] = char_code
37
+ end
38
+
39
+ def increment(count = 1)
40
+ @tables[@pointer] = 0 unless @tables[@pointer]
41
+ @tables[@pointer] += count
42
+ @config.increment * count
43
+ end
44
+
45
+ def decrement(count = 1)
46
+ @tables[@pointer] -= count
47
+ @config.decrement * count
48
+ end
49
+
50
+ def diff(char_code)
51
+ diff_of_code = char_code - @tables[@pointer]
52
+ return '' if diff_of_code.zero?
53
+ @tables[@pointer] += diff_of_code
54
+ diff_of_code > 0 ? (@config.increment * diff_of_code) : (@config.decrement * diff_of_code.abs)
55
+ end
56
+
57
+ def next_pointer(count = 1)
58
+ @pointer += count
59
+ @config.next_cursol * count
60
+ end
61
+
62
+ def previous_pointer(count = 1)
63
+ @pointer -= count
64
+ @config.previous_cursol * count
65
+ end
66
+
67
+ def output(count = 1)
68
+ @config.display * count
69
+ end
70
+
71
+ private
72
+
73
+ def ten_increment(config)
74
+ config.increment * 10
75
+ end
76
+ end
77
+ end
78
+ # rubocop:enable LineLength
@@ -1,4 +1,4 @@
1
1
  # Orenono
2
2
  module Orenono
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.3'
4
4
  end
@@ -1,71 +1,87 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'generator'
4
-
5
- # rubocop:disable Tab, UnusedMethodArgument, LineLength
6
- describe Orenono::Generator do
7
- context :generate do
8
- cases = [
9
- {
10
- case_no: 1,
11
- case_title: 'default case',
12
- config: Orenono::DslModel.new.tap do |e|
13
- e.increment = '+'
14
- e.decrement = '-'
15
- e.start_loop = '['
16
- e.end_loop = ']'
17
- e.next_cursol = '>'
18
- e.previous_cursol = '<'
19
- e.display = '.'
20
- e.read = ','
21
- end,
22
- text: 'Hello, world!',
23
- expected: '++++++++++[>+++++++<-]>++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.'
24
- },
25
- {
26
- case_no: 2,
27
- case_title: 'original case',
28
- config: Orenono::DslModel.new.tap do |e|
29
- e.increment = 'add'
30
- e.decrement = 'diff'
31
- e.start_loop = 'start'
32
- e.end_loop = 'end'
33
- e.next_cursol = 'next'
34
- e.previous_cursol = 'previous'
35
- e.display = 'display'
36
- e.read = 'read'
37
- end,
38
- text: 'Hello, world!',
39
- expected: 'addaddaddaddaddaddaddaddaddaddstartnextaddaddaddaddaddaddaddpreviousdiffendnextaddadddisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplayaddaddaddaddaddaddadddisplaydisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplay'
40
- }
41
- ]
42
-
43
- cases.each do |c|
44
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
45
- begin
46
- case_before c
47
-
48
- # -- given --
49
- # nothing
50
-
51
- # -- when --
52
- actual = Orenono::Generator.generate(c[:text], c[:config])
53
-
54
- # -- then --
55
- expect(actual).to eq(c[:expected])
56
- ensure
57
- case_after c
58
- end
59
- end
60
-
61
- def case_before(c)
62
- # implement each case before
63
- end
64
-
65
- def case_after(c)
66
- # implement each case after
67
- end
68
- end
69
- end
70
- end
71
- # rubocop:enable Tab, UnusedMethodArgument, LineLength
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'generator'
4
+
5
+ # rubocop:disable Tab, UnusedMethodArgument, LineLength
6
+ describe Orenono::Generator do
7
+ context :generate do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'default case',
12
+ config: Orenono::DslModel.new.tap do |e|
13
+ e.increment = '+'
14
+ e.decrement = '-'
15
+ e.start_loop = '['
16
+ e.end_loop = ']'
17
+ e.next_cursol = '>'
18
+ e.previous_cursol = '<'
19
+ e.display = '.'
20
+ e.read = ','
21
+ end,
22
+ text: 'Hello, world!',
23
+ expected: '++++++++++[>+++++++<-]>++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.'
24
+ },
25
+ {
26
+ case_no: 2,
27
+ case_title: 'original case',
28
+ config: Orenono::DslModel.new.tap do |e|
29
+ e.increment = 'add'
30
+ e.decrement = 'diff'
31
+ e.start_loop = 'start'
32
+ e.end_loop = 'end'
33
+ e.next_cursol = 'next'
34
+ e.previous_cursol = 'previous'
35
+ e.display = 'display'
36
+ e.read = 'read'
37
+ end,
38
+ text: 'Hello, world!',
39
+ expected: 'addaddaddaddaddaddaddaddaddaddstartnextaddaddaddaddaddaddaddpreviousdiffendnextaddadddisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplayaddaddaddaddaddaddadddisplaydisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddaddadddisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplayaddaddadddisplaydiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdisplaydiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdiffdisplay'
40
+ },
41
+ {
42
+ case_no: 3,
43
+ case_title: 'multibyte case',
44
+ config: Orenono::DslModel.new.tap do |e|
45
+ e.increment = '+'
46
+ e.decrement = '-'
47
+ e.start_loop = '['
48
+ e.end_loop = ']'
49
+ e.next_cursol = '>'
50
+ e.previous_cursol = '<'
51
+ e.display = '.'
52
+ e.read = ','
53
+ end,
54
+ text: 'こんにちわ世界',
55
+ expected: '++++++++++[>++++++++++++++++++++++<-]>+++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------.+++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------.+++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------.----------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------------------------------------------------------------------.---------.'
56
+ }
57
+ ]
58
+
59
+ cases.each do |c|
60
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
+ begin
62
+ case_before c
63
+
64
+ # -- given --
65
+ # nothing
66
+
67
+ # -- when --
68
+ actual = Orenono::Generator.generate(c[:text], c[:config])
69
+
70
+ # -- then --
71
+ expect(actual).to eq(c[:expected])
72
+ ensure
73
+ case_after c
74
+ end
75
+ end
76
+
77
+ def case_before(c)
78
+ # implement each case before
79
+ end
80
+
81
+ def case_after(c)
82
+ # implement each case after
83
+ end
84
+ end
85
+ end
86
+ end
87
+ # rubocop:enable Tab, UnusedMethodArgument, LineLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orenono
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - .rspec
66
66
  - .rubocop.yml
67
67
  - .travis.yml
68
+ - CHANGELOG.md
68
69
  - Gemfile
69
70
  - LICENSE.txt
70
71
  - README.md
@@ -121,3 +122,4 @@ test_files:
121
122
  - spec/generator_spec.rb
122
123
  - spec/orenono_core_spec.rb
123
124
  - spec/spec_helper.rb
125
+ has_rdoc: