-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding more specs, and better subclassing
- Loading branch information
1 parent
dc81874
commit a67c063
Showing
15 changed files
with
8,641 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec | ||
|
||
gem 'guard' | ||
gem 'guard-rspec', '~> 4.3.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard :rspec, cmd: 'bundle exec rspec' do | ||
# watch(%r{^spec/.+_spec\.rb$}) { "spec" } | ||
watch(%r{^spec/.+_spec\.rb$}) { |m| m[0] } | ||
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
module PrisonParser | ||
module Models | ||
class Base < Node | ||
def initialize | ||
class_name = self.class.name | ||
label = class_name[(class_name.rindex("::") + 2)..-1] | ||
def initialize(label=nil) | ||
label ||= self.class.name[(self.class.name.rindex("::") + 2)..-1] | ||
super(label) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module PrisonParser | ||
module Models | ||
class Cell < Base | ||
|
||
attr_reader :x, :y | ||
|
||
def initialize(x=0, y=0) | ||
@x = x | ||
@y = y | ||
super("#{x} #{y}") | ||
end | ||
|
||
def material | ||
properties['Mat'] | ||
end | ||
|
||
# 0 worst, 100 best | ||
def condition | ||
return nil unless properties.has_key?('Con') | ||
properties['Con'].to_f | ||
end | ||
|
||
def room_id | ||
return nil unless properties.has_key?('Room.i') | ||
properties['Room.i'].to_i | ||
end | ||
|
||
def room_uid | ||
return nil unless properties.has_key?('Room.u') | ||
properties['Room.u'].to_i | ||
end | ||
|
||
def room | ||
# TODO: Return the room object? | ||
end | ||
|
||
def indoors? | ||
"true" == properties['Ind'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module PrisonParser | ||
module Models | ||
class Cells < Base | ||
|
||
def initialize(width=100, height=100) | ||
@cells = (0...width).map { Array.new(height) } | ||
super("Cells") | ||
end | ||
|
||
def [](x,y) | ||
@cells[x][y] | ||
end | ||
|
||
def <<(cell) | ||
@cells[cell.x][cell.y] = cell | ||
end | ||
|
||
def each | ||
@cells.flatten.compact.each do |cell| | ||
yield(cell) | ||
end | ||
end | ||
|
||
def create_node(label) | ||
x, y = label.split.map(&:to_i) | ||
@cells[x][y] = Cell.new(x, y) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.