logor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/logor +24 -0
- data/lib/logor.rb +91 -0
- data/lib/logor/version.rb +3 -0
- data/logor.gemspec +23 -0
- data/spec/logor_spec.rb +86 -0
- data/spec/spec_helper.rb +18 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWEyODZmNTZmZDY4YWFhZjE0MzdkOWZjNDJlOTFiZTc3NDk4YzRjZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWE1MjRmZjc2MzI3MWMyYmI3MWU0NmM1MGY0YzA5YzA1OWFiOGY5Nw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzFkNjNhMTk3NjQ0YTU5MzFhNWUzN2VjZjVmYjE1NmFlM2Q0N2Y4MDY1MTQ0
|
10
|
+
MjJmOTRhNjMzZDdhOTFmN2Q2YjA4NDUxNTQzMjNiMmQ4ZTFjMmE3NjQ1OTk2
|
11
|
+
OWFjYTUyMzRiZGQzMmQ5ZGYwMzdlM2ZjNzQ5ZWE0OTIzYjExMzg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzUxNjlhMWVhYTI3ZGM1ZDQyOTZjNTJiMjVjZTEwZDQzMWZiZjU4NWI2N2E1
|
14
|
+
NWQxN2VjYTUwYTllY2I1NTE5MjkzMDhlZDZlYTg1YzI0NTFjZDQ4ZGI0ZDY1
|
15
|
+
ZmVmOWMxY2ZlYjhmNTkyNjk1YTlkOGIyYzdkYWY0ZDMwN2VhN2U=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michał Marcinkowski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Logor
|
2
|
+
|
3
|
+
Basic LOGO interpreter
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'logor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install logor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create new area. N is an odd number greater than 1.
|
22
|
+
|
23
|
+
$ logor N
|
24
|
+
|
25
|
+
Enter command.
|
26
|
+
>Availible commands:
|
27
|
+
* "U X" - move up X units
|
28
|
+
* "D X" - move down X units
|
29
|
+
* "R X" - move right X units
|
30
|
+
* "L X" - move left X units
|
31
|
+
* "Q" - quit
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/mmarcinkowski/logo/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/logor
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'logor'
|
4
|
+
|
5
|
+
arr=NewLogo.new(ARGV[0].to_i)
|
6
|
+
if arr.flag
|
7
|
+
begin
|
8
|
+
arr.view
|
9
|
+
print "\nEnter command: "
|
10
|
+
arg = STDIN.gets
|
11
|
+
if arg=="\n" then arg="empty" end
|
12
|
+
command = arg.to_s.split
|
13
|
+
case command[0].upcase
|
14
|
+
when "U"
|
15
|
+
arr.up(command[1].to_i)
|
16
|
+
when "D"
|
17
|
+
arr.down(command[1].to_i)
|
18
|
+
when "L"
|
19
|
+
arr.left(command[1].to_i)
|
20
|
+
when "R"
|
21
|
+
arr.right(command[1].to_i)
|
22
|
+
end
|
23
|
+
end while not command[0].upcase=="Q"
|
24
|
+
end
|
data/lib/logor.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "logor/version"
|
2
|
+
|
3
|
+
class NewLogo
|
4
|
+
attr_accessor :pointer, :a, :flag
|
5
|
+
def initialize(n)
|
6
|
+
@size=n
|
7
|
+
if @size%2!=0 && @size>1
|
8
|
+
@a = Array.new(@size) { Array.new(@size,".")}
|
9
|
+
@a[@size/2][@size/2]="X"
|
10
|
+
@pointer=[@size/2,@size/2]
|
11
|
+
@flag=true
|
12
|
+
else
|
13
|
+
@flag=false
|
14
|
+
puts "Enter an odd number greater than 1."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def [](x,y)
|
19
|
+
@a[x][y]
|
20
|
+
end
|
21
|
+
|
22
|
+
def []=(x,y,value)
|
23
|
+
@a[x][y]=value
|
24
|
+
end
|
25
|
+
|
26
|
+
def view
|
27
|
+
system 'clear'
|
28
|
+
@a.each {|x| puts x.map{|y| y}.join(" ")}
|
29
|
+
end
|
30
|
+
|
31
|
+
def up(value)
|
32
|
+
start=@pointer[0]
|
33
|
+
@pointer[0]-=value
|
34
|
+
goal=@pointer[0]
|
35
|
+
print @pointer
|
36
|
+
if goal >= 0
|
37
|
+
while start!=goal
|
38
|
+
start-=1
|
39
|
+
@a[start][@pointer[1]]="X"
|
40
|
+
end
|
41
|
+
else
|
42
|
+
@pointer[0]=start
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def down(value)
|
47
|
+
start=@pointer[0]
|
48
|
+
@pointer[0]+=value
|
49
|
+
goal=@pointer[0]
|
50
|
+
print @pointer
|
51
|
+
if goal < @size
|
52
|
+
while start!=goal
|
53
|
+
start+=1
|
54
|
+
@a[start][@pointer[1]]="X"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@pointer[0]=start
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def left(value)
|
62
|
+
start=@pointer[1]
|
63
|
+
@pointer[1]-=value
|
64
|
+
goal=@pointer[1]
|
65
|
+
print @pointer
|
66
|
+
if goal >= 0
|
67
|
+
while start!=goal
|
68
|
+
start-=1
|
69
|
+
@a[@pointer[0]][start]="X"
|
70
|
+
end
|
71
|
+
else
|
72
|
+
@pointer[1]=start
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def right(value)
|
77
|
+
start=@pointer[1]
|
78
|
+
@pointer[1]+=value
|
79
|
+
goal=@pointer[1]
|
80
|
+
print @pointer
|
81
|
+
if goal < @size
|
82
|
+
while start!=goal
|
83
|
+
start+=1
|
84
|
+
@a[@pointer[0]][start]="X"
|
85
|
+
end
|
86
|
+
else
|
87
|
+
@pointer[1]=start
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/logor.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logor"
|
8
|
+
spec.version = Logor::VERSION
|
9
|
+
spec.authors = ["Michał Marcinkowski"]
|
10
|
+
spec.email = ["michal.marcinkovski@gmail.com"]
|
11
|
+
spec.summary = %q{Basic LOGO interpreter}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/mmarcinkowski/logor.git"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
end
|
data/spec/logor_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NewLogo do
|
4
|
+
|
5
|
+
describe "initialize with valid argument." do
|
6
|
+
arr = NewLogo.new(5)
|
7
|
+
|
8
|
+
it { expect(arr.flag).to be_true }
|
9
|
+
it { expect(arr.pointer[0]).to eq(2) }
|
10
|
+
it { arr.a[2][2].should include("X") }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "initialize with invalid argument" do
|
14
|
+
bad_arr = NewLogo.new(1)
|
15
|
+
|
16
|
+
it { expect(bad_arr.flag).to be_false }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "pointer moving up with " do
|
20
|
+
arr = NewLogo.new(5)
|
21
|
+
|
22
|
+
describe "valid argument." do
|
23
|
+
|
24
|
+
arr.up(2)
|
25
|
+
it { expect(arr.pointer).to eq([0,2]) }
|
26
|
+
it { arr.a[0][2].should include("X") }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "invalid argument." do
|
30
|
+
|
31
|
+
arr.up(20)
|
32
|
+
it { expect(arr.pointer).to eq([0,2]) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "pointer moving down with " do
|
37
|
+
arr = NewLogo.new(5)
|
38
|
+
|
39
|
+
describe "valid argument." do
|
40
|
+
|
41
|
+
arr.down(2)
|
42
|
+
it { expect(arr.pointer).to eq([4,2]) }
|
43
|
+
it { arr.a[4][2].should include("X") }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "invalid argument." do
|
47
|
+
|
48
|
+
arr.down(20)
|
49
|
+
it { expect(arr.pointer).to eq([4,2]) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "pointer moving right with " do
|
54
|
+
arr = NewLogo.new(5)
|
55
|
+
|
56
|
+
describe "valid argument." do
|
57
|
+
|
58
|
+
arr.right(2)
|
59
|
+
it { expect(arr.pointer).to eq([2,4]) }
|
60
|
+
it { arr.a[2][4].should include("X") }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "invalid argument." do
|
64
|
+
|
65
|
+
arr.right(20)
|
66
|
+
it { expect(arr.pointer).to eq([2,4]) }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "pointer moving right with " do
|
71
|
+
arr = NewLogo.new(5)
|
72
|
+
|
73
|
+
describe "valid argument." do
|
74
|
+
|
75
|
+
arr.left(2)
|
76
|
+
it { expect(arr.pointer).to eq([2,0]) }
|
77
|
+
it { arr.a[2][0].should include("X") }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "invalid argument." do
|
81
|
+
|
82
|
+
arr.left(20)
|
83
|
+
it { expect(arr.pointer).to eq([2,0]) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'logor'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
|
+
# loaded once.
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michał Marcinkowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- michal.marcinkovski@gmail.com
|
44
|
+
executables:
|
45
|
+
- logor
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/logor
|
56
|
+
- lib/logor.rb
|
57
|
+
- lib/logor/version.rb
|
58
|
+
- logor.gemspec
|
59
|
+
- spec/logor_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: https://github.com/mmarcinkowski/logor.git
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Basic LOGO interpreter
|
85
|
+
test_files:
|
86
|
+
- spec/logor_spec.rb
|
87
|
+
- spec/spec_helper.rb
|