puzzle_reader 0.0.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.
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +30 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/puzzle_reader.rb +52 -0
- data/mock_file +15 -0
- data/spec/data/sample-input.txt +15 -0
- data/spec/puzzle_reader_spec.rb +33 -0
- data/spec/spec_helper.rb +13 -0
- data/test +1 -0
- metadata +108 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :test do
|
9
|
+
gem "rspec", ">= 0"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem "pry" , ">= 0"
|
14
|
+
gem "rdoc", "~> 3.12"
|
15
|
+
gem "bundler", "~> 1.0.0"
|
16
|
+
gem "jeweler", "~> 1.8.3"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.6)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.3)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.7.1)
|
13
|
+
method_source (0.7.1)
|
14
|
+
pry (0.9.9.6)
|
15
|
+
coderay (~> 1.0.5)
|
16
|
+
method_source (~> 0.7.1)
|
17
|
+
slop (>= 2.4.4, < 3)
|
18
|
+
rake (0.9.2.2)
|
19
|
+
rdoc (3.12)
|
20
|
+
json (~> 1.4)
|
21
|
+
rspec (2.10.0)
|
22
|
+
rspec-core (~> 2.10.0)
|
23
|
+
rspec-expectations (~> 2.10.0)
|
24
|
+
rspec-mocks (~> 2.10.0)
|
25
|
+
rspec-core (2.10.0)
|
26
|
+
rspec-expectations (2.10.0)
|
27
|
+
diff-lcs (~> 1.1.3)
|
28
|
+
rspec-mocks (2.10.1)
|
29
|
+
slop (2.4.4)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 1.0.0)
|
36
|
+
jeweler (~> 1.8.3)
|
37
|
+
pry
|
38
|
+
rdoc (~> 3.12)
|
39
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Peter Jurczyński
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= puzzle_reader
|
2
|
+
|
3
|
+
It is a gem that reads a certain format of the PuzzleNode input data:
|
4
|
+
For each test case output a single line with the dictionary word that has the longest common sub-sequence with the search query word. ex.:
|
5
|
+
|
6
|
+
2 #number of test cases
|
7
|
+
|
8
|
+
3 #number of rows in a data set
|
9
|
+
one
|
10
|
+
two
|
11
|
+
three
|
12
|
+
|
13
|
+
2 #number of rows in a data set
|
14
|
+
awesome
|
15
|
+
tribute
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
it is simple as:
|
20
|
+
|
21
|
+
data = PuzzleReader.read(input_file)
|
22
|
+
|
23
|
+
Now you can access your data as an array:
|
24
|
+
|
25
|
+
data[0][1] # second row in the first test case - "two"
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2012 Peter Jurczyński. See LICENSE.txt for
|
30
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "puzzle_reader"
|
18
|
+
gem.homepage = "http://github.com/pjurczynski/puzzle_reader"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Extracts input from PuzzleNode puzzles}
|
21
|
+
gem.description = %Q{This gem is only for a couple PuzzleNode puzzles. For the time being it was created specially for Puzzle #2 and #3}
|
22
|
+
gem.email = "pjurczynski@gmail.com"
|
23
|
+
gem.authors = ["Peter Jurczyński"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "puzzle_reader #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PuzzleReader
|
2
|
+
def self.read(puzzle_file)
|
3
|
+
File.open puzzle_file do |f|
|
4
|
+
@test_cases = DataSet.new(f.lines)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class DataSet
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def self
|
12
|
+
@data
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@data ||= []
|
17
|
+
begin
|
18
|
+
current_row = data.next.strip!
|
19
|
+
peek_row = data.peek.strip
|
20
|
+
return if current_row.nil?
|
21
|
+
end while current_row.empty?
|
22
|
+
|
23
|
+
if current_row =~ /^\d*$/
|
24
|
+
rows = current_row.to_i.times
|
25
|
+
if peek_row.empty?
|
26
|
+
rows.each { @data << DataSet.new(data) }
|
27
|
+
else
|
28
|
+
rows.each { @data << DataRow.new(data) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def each
|
34
|
+
data.each
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(m, *args, &block)
|
38
|
+
begin
|
39
|
+
@data.send(m, *args, &block)
|
40
|
+
rescue NoMethodError
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class DataRow < DataSet
|
47
|
+
|
48
|
+
def initialize(data)
|
49
|
+
@data = data.next.to_s.strip
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/mock_file
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
2
|
2
|
+
|
3
|
+
3
|
4
|
+
A B 09:00 10:00 100.00
|
5
|
+
B Z 11:30 13:30 100.00
|
6
|
+
A Z 10:00 12:00 300.00
|
7
|
+
|
8
|
+
7
|
9
|
+
A B 08:00 09:00 50.00
|
10
|
+
A B 12:00 13:00 300.00
|
11
|
+
A C 14:00 15:30 175.00
|
12
|
+
B C 10:00 11:00 75.00
|
13
|
+
B Z 15:00 16:30 250.00
|
14
|
+
C B 15:45 16:45 50.00
|
15
|
+
C Z 16:00 19:00 100.00
|
@@ -0,0 +1,15 @@
|
|
1
|
+
2
|
2
|
+
|
3
|
+
3
|
4
|
+
A B 09:00 10:00 100.00
|
5
|
+
B Z 11:30 13:30 100.00
|
6
|
+
A Z 10:00 12:00 300.00
|
7
|
+
|
8
|
+
7
|
9
|
+
A B 08:00 09:00 50.00
|
10
|
+
A B 12:00 13:00 300.00
|
11
|
+
A C 14:00 15:30 175.00
|
12
|
+
B C 10:00 11:00 75.00
|
13
|
+
B Z 15:00 16:30 250.00
|
14
|
+
C B 15:45 16:45 50.00
|
15
|
+
C Z 16:00 19:00 100.00
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
module PuzzleReader
|
4
|
+
describe self do
|
5
|
+
before(:each) do
|
6
|
+
File.open('spec/data/sample-input.txt', 'r') do |f|
|
7
|
+
@data = PuzzleReader.read(f)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should assaign data set with a given input" do
|
12
|
+
@data.should be_a_kind_of DataSet
|
13
|
+
@data[0].should be_a_kind_of DataSet
|
14
|
+
@data[0][0].should be_a_kind_of DataRow
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#data" do
|
18
|
+
it "should have return data" do
|
19
|
+
@data[0][0].data.should be == "A B 09:00 10:00 100.00"
|
20
|
+
@data[0][1].data.should be == "B Z 11:30 13:30 100.00"
|
21
|
+
@data[0][2].data.should be == "A Z 10:00 12:00 300.00"
|
22
|
+
|
23
|
+
@data[1][0].data.should be == "A B 08:00 09:00 50.00"
|
24
|
+
@data[1][1].data.should be == "A B 12:00 13:00 300.00"
|
25
|
+
@data[1][2].data.should be == "A C 14:00 15:30 175.00"
|
26
|
+
@data[1][3].data.should be == "B C 10:00 11:00 75.00"
|
27
|
+
@data[1][4].data.should be == "B Z 15:00 16:30 250.00"
|
28
|
+
@data[1][5].data.should be == "C B 15:45 16:45 50.00"
|
29
|
+
@data[1][6].data.should be == "C Z 16:00 19:00 100.00"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development, :test)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'pry'
|
13
|
+
require_relative '../lib/puzzle_reader'
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puzzle_reader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Jurczyński
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: &18803660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18803660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &18820680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.12'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *18820680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &18819960 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *18819960
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &18819100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.3
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *18819100
|
58
|
+
description: ! 'This gem is only for a couple PuzzleNode puzzles. For the time being
|
59
|
+
it was created specially for Puzzle #2 and #3'
|
60
|
+
email: pjurczynski@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.rdoc
|
66
|
+
files:
|
67
|
+
- .document
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- VERSION
|
74
|
+
- lib/puzzle_reader.rb
|
75
|
+
- mock_file
|
76
|
+
- spec/data/sample-input.txt
|
77
|
+
- spec/puzzle_reader_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- test
|
80
|
+
homepage: http://github.com/pjurczynski/puzzle_reader
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -501870726576038013
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.17
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Extracts input from PuzzleNode puzzles
|
108
|
+
test_files: []
|