confire 0.0.2
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.
- checksums.yaml +7 -0
- data/bin/confire +21 -0
- data/lib/confire.rb +10 -0
- data/lib/confire/project_creator.rb +29 -0
- data/lib/confire/templates/Gemfile +10 -0
- data/lib/confire/templates/Rakefile +6 -0
- data/lib/confire/templates/config.yml +3 -0
- data/lib/confire/templates/input_sample.txt +7 -0
- data/lib/confire/templates/main.rb +44 -0
- data/lib/confire/templates/parser.rb +51 -0
- data/lib/confire/templates/processor.rb +13 -0
- data/lib/confire/templates/run.sh +3 -0
- data/lib/confire/templates/spec/processor_spec.rb +29 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c458e06c91a29c4267a3433a3df20e44cb5e2808
|
4
|
+
data.tar.gz: bd16381296df5b286d7623aa551c71ed415aa075
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d203311de72b0aabfa4f381a96d814f7d732fecc41d5a783bbb6c9f27b68659ea839485a4543c2a5b2c1064ded89b5aa73f5d1e168ab0989f8a42cd00b7256c
|
7
|
+
data.tar.gz: 567faa9cebbd737b8429b8c2ed223828a260039fea509147e1f6a03302779f9efa3f0a693b23a72e19a7d89c62c8dd6c28c00616d4812cb54de03269092a3076
|
data/bin/confire
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'confire'
|
4
|
+
|
5
|
+
def usage
|
6
|
+
puts 'usage: confire [project_name]'
|
7
|
+
end
|
8
|
+
|
9
|
+
if ARGV.length == 1
|
10
|
+
# test to see if that dir exists already
|
11
|
+
project_name = ARGV[0]
|
12
|
+
unless File.directory?(project_name)
|
13
|
+
confire = Confire.new project_name
|
14
|
+
else
|
15
|
+
puts 'Please choose another project name as that directory already exists'
|
16
|
+
usage
|
17
|
+
end
|
18
|
+
else
|
19
|
+
puts 'Wrong number of arguments'
|
20
|
+
usage
|
21
|
+
end
|
data/lib/confire.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class ProjectCreator
|
2
|
+
def create(project_name)
|
3
|
+
# make dir with that project_name
|
4
|
+
Dir.mkdir project_name
|
5
|
+
|
6
|
+
# copy files in
|
7
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/config.yml'), project_name)
|
8
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/Gemfile'), project_name)
|
9
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/main.rb'), project_name)
|
10
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/Rakefile'), project_name)
|
11
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/processor.rb'), project_name)
|
12
|
+
FileUtils.cp_r(filename_with_path('lib/confire/templates/spec'), project_name)
|
13
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/parser.rb'), project_name)
|
14
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/run.sh'), project_name)
|
15
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/input_sample.txt'), project_name)
|
16
|
+
#copy_and_rename project_name, 'lib/confire/templates/config_sample.yml', 'config_sample.yml', 'config.yml'
|
17
|
+
#copy_and_rename project_name, 'lib/confire/templates/processor.rb', 'config_sample.yml', 'config.yml'
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
def filename_with_path(filename)
|
22
|
+
File.join(Confire.root, filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_and_rename(project_name, source, oldname, newname)
|
26
|
+
FileUtils.cp(source, project_name)
|
27
|
+
FileUtils.mv(File.join(project_name, oldname), File.join(project_name, newname))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'log4r'
|
3
|
+
require_relative 'parser'
|
4
|
+
require_relative 'processor'
|
5
|
+
include Log4r
|
6
|
+
|
7
|
+
class Main
|
8
|
+
def initialize
|
9
|
+
# setup configs
|
10
|
+
config = YAML::load_file(File.join(__dir__, 'config.yml'))
|
11
|
+
filename = config['filename']
|
12
|
+
lines_per_test_case = config['lines_per_test_case']
|
13
|
+
|
14
|
+
# setup parser
|
15
|
+
@parser = Parser.new(
|
16
|
+
filename: filename,
|
17
|
+
lines_per_test_case: lines_per_test_case
|
18
|
+
)
|
19
|
+
|
20
|
+
# setup logger
|
21
|
+
logger = Logger.new 'application_logger'
|
22
|
+
logger.outputters = Outputter.stdout
|
23
|
+
logger.level = config['log_level']
|
24
|
+
@logger = logger
|
25
|
+
|
26
|
+
# setup processor that will do all the work
|
27
|
+
@processor = Processor.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
block_processor = ->(line_buffer, test_number) do
|
32
|
+
processed_block = @processor.process_block line_buffer, test_number
|
33
|
+
puts "#{test_number}: #{processed_block}"
|
34
|
+
end
|
35
|
+
|
36
|
+
line_processor = ->(line) do
|
37
|
+
@processor.process_line line
|
38
|
+
end
|
39
|
+
|
40
|
+
@parser.parse block_processor, line_processor
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Main.new.run
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Parses the google test case
|
2
|
+
class Parser
|
3
|
+
attr_accessor :filename, :lines_per_test_case
|
4
|
+
|
5
|
+
# Remember to set:
|
6
|
+
# filename to read (will blow a ArgumentError if not set)
|
7
|
+
# lines_per_test_case
|
8
|
+
def initialize(options = {})
|
9
|
+
@filename = options[:filename]
|
10
|
+
@lines_per_test_case = options[:lines_per_test_case] || 1
|
11
|
+
end
|
12
|
+
|
13
|
+
# This will read a given test case and pass that into the test_case_processor.
|
14
|
+
# A test case is defined as the number of lines_per_test_case
|
15
|
+
# Can optionally pass in a line_processor that will process a line before adding it to the buffer.
|
16
|
+
# Will stop reading after we hit the number of test cases defined in the file
|
17
|
+
# Assumption: Number of test cases is defined in the first line
|
18
|
+
def parse(test_case_processor, line_processor = nil)
|
19
|
+
(raise ArgumentError.new('Missing input filename to parse')) unless @filename
|
20
|
+
line_counter = -1
|
21
|
+
test_cases_read = 0
|
22
|
+
|
23
|
+
test_cases = 0
|
24
|
+
line_buffer = []
|
25
|
+
|
26
|
+
IO.foreach(@filename) do |line|
|
27
|
+
line.strip!
|
28
|
+
# read number of cases
|
29
|
+
if line_counter == -1
|
30
|
+
test_cases = line.to_i
|
31
|
+
# if unable to parse or we get 0, blow up
|
32
|
+
raise ArgumentError.new('Missing number of test cases on first line') if test_cases == 0
|
33
|
+
line_counter = 0
|
34
|
+
# process the test case
|
35
|
+
elsif line_counter == (lines_per_test_case - 1)
|
36
|
+
line = line_processor.call(line) if line_processor
|
37
|
+
line_buffer << line
|
38
|
+
test_cases_read += 1
|
39
|
+
test_case_processor.call(line_buffer, test_cases_read)
|
40
|
+
line_buffer = []
|
41
|
+
line_counter = 0
|
42
|
+
return if test_cases_read == test_cases
|
43
|
+
# keep reading
|
44
|
+
else
|
45
|
+
line = line_processor.call(line) if line_processor
|
46
|
+
line_buffer << line
|
47
|
+
line_counter += 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This is where the main bits are processed
|
2
|
+
# We can process lines and blocks here
|
3
|
+
class Processor
|
4
|
+
# Will process a test case. simply return whatever we want to print out as results
|
5
|
+
def process_block(line_buffer, test_number)
|
6
|
+
line_buffer
|
7
|
+
end
|
8
|
+
|
9
|
+
# Process the line to be stored in the line_buffer
|
10
|
+
def process_line(line)
|
11
|
+
line.split ' '
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../processor'
|
3
|
+
|
4
|
+
describe Processor do
|
5
|
+
before do
|
6
|
+
@processor = Processor.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when asked to process a test case" do
|
10
|
+
it "must process it" do
|
11
|
+
test_number = 1
|
12
|
+
line_buffer = [["5", "5", "23"], ["3", "1", "1"]]
|
13
|
+
expected = [["5", "5", "23"], ["3", "1", "1"]]
|
14
|
+
|
15
|
+
actual = @processor.process_block line_buffer, test_number
|
16
|
+
actual.must_equal expected
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "when asked to process a line" do
|
21
|
+
it "must process it" do
|
22
|
+
line = "5 5 23"
|
23
|
+
expected = ["5", "5", "23"]
|
24
|
+
|
25
|
+
actual = @processor.process_line line
|
26
|
+
actual.must_equal expected
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Keam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Setups the necessary classes and tests for a codejam solution.
|
14
|
+
email: jpkeam@gmail.com
|
15
|
+
executables:
|
16
|
+
- confire
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/confire
|
21
|
+
- lib/confire.rb
|
22
|
+
- lib/confire/project_creator.rb
|
23
|
+
- lib/confire/templates/Gemfile
|
24
|
+
- lib/confire/templates/Rakefile
|
25
|
+
- lib/confire/templates/config.yml
|
26
|
+
- lib/confire/templates/input_sample.txt
|
27
|
+
- lib/confire/templates/main.rb
|
28
|
+
- lib/confire/templates/parser.rb
|
29
|
+
- lib/confire/templates/processor.rb
|
30
|
+
- lib/confire/templates/run.sh
|
31
|
+
- lib/confire/templates/spec/processor_spec.rb
|
32
|
+
homepage: http://rubygems.org/gems/confire
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.2.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Very easy project setup for google codejam problems
|
56
|
+
test_files: []
|