Skip to content

Common generate script #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ tree -L 1 ~/code/exercism
1. `xruby/$PROBLEM/example.tt` - the Erb template for the test file, `$PROBLEM_test.rb`.
1. `x-common/$PROBLEM.json` - the shared inputs and outputs for the problem.
1. `lib/$PROBLEM.rb` - the logic for turning the data into tests.
1. `xruby/bin/generate-$PROBLEM` - the command to actually generate the test suite.
1. `xruby/bin/generate $PROBLEM` - the command to actually generate the test suite.
1. `.version` - used to keep track of the version of the test files as the data changes.

Additionally, there is some common generator logic in `lib/generator.rb`.
Expand All @@ -98,7 +98,7 @@ For example, take a look at the `hamming.json` file in the x-common repository,
as the following files in the xruby repository:

1. `hamming/example.tt`
1. `bin/generate-hamming`
1. `bin/generate hamming`
1. `lib/hamming.rb`
1. `lib/generator.rb`

Expand Down Expand Up @@ -166,4 +166,4 @@ The MIT License (MIT)
Copyright (c) 2014 Katrina Owen, _@kytrinyx.com

## Ruby icon
The Ruby icon is the Vienna.rb logo, and is used with permission. Thanks Floor Dress :)
The Ruby icon is the Vienna.rb logo, and is used with permission. Thanks Floor Dress :)
16 changes: 16 additions & 0 deletions bin/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby

exercise = ARGV[0]
cases = "#{exercise.tr('-','_')}_cases"

require_relative '../lib/helper'
require 'generator'
begin
require "#{cases}"
rescue LoadError
puts "A generator does not currently exist for #{exercise}!"
exit(1)
end

klass = Object.const_get(cases.split('_').map(&:capitalize).join)
Generator.new(exercise, klass).generate
7 changes: 0 additions & 7 deletions bin/generate-acronym

This file was deleted.

8 changes: 0 additions & 8 deletions bin/generate-alphametics

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-binary

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-bracket-push

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-clock

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-connect

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-custom-set

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-difference-of-squares

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-gigasecond

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-hamming

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-hello-world

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-largest-series-product

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-leap

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-nth-prime

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-pangram

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-raindrops

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-rna-transcription

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-roman-numerals

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-run-length-encoding

This file was deleted.

7 changes: 0 additions & 7 deletions bin/generate-two-bucket

This file was deleted.

6 changes: 3 additions & 3 deletions lib/bracket_push_cases.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BracketsCase < OpenStruct
class BracketPushCase < OpenStruct
def name
'test_%s' % description.gsub(/[ -]/, '_')
end
Expand Down Expand Up @@ -34,8 +34,8 @@ def split_input
end
end

BracketsCases = proc do |data|
BracketPushCases = proc do |data|
JSON.parse(data)['cases'].map.with_index do |row, i|
BracketsCase.new(row.merge('index' => i))
BracketPushCase.new(row.merge('index' => i))
end
end
2 changes: 1 addition & 1 deletion lib/raindrop_cases.rb → lib/raindrops_cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def skipped?
end
end

RaindropCases = proc do |data|
RaindropsCases = proc do |data|
JSON.parse(data)['cases'].map.with_index do |row, i|
RaindropsCase.new(row.merge('index' => i))
end
Expand Down