greyhawkweather 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/History.txt +5 -0
- data/Manifest.txt +16 -14
- data/Rakefile +10 -22
- data/bin/greyweathergen +6 -2
- data/greyhawkweather.gemspec +33 -0
- data/lib/baselinedata.rb +1 -3
- data/lib/greyhawkweather.rb +2 -3
- data/lib/greyhawkweather/version.rb +4 -0
- data/lib/greyhawkweathergenerator.rb +4 -6
- data/lib/options.rb +15 -0
- data/lib/precipitationoccurance.rb +8 -4
- data/lib/singledayweather.rb +11 -3
- data/lib/skyconditions.rb +1 -1
- data/lib/temperaturerange.rb +10 -2
- data/lib/util/dieroller.rb +3 -3
- data/lib/weathergenerator.rb +15 -9
- data/lib/wind.rb +3 -1
- data/spec/acceptance_spec.rb +52 -0
- data/spec/dieroller_spec.rb +22 -0
- data/spec/latitude_spec.rb +25 -0
- data/spec/month_spec.rb +34 -0
- data/spec/options_spec.rb +25 -0
- data/spec/precipation_spec.rb +23 -0
- data/spec/precipitation_occurance_spec.rb +114 -0
- data/spec/singledayweather_spec.rb +44 -0
- data/spec/sky_conditions_spec.rb +20 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/temperature_range_spec.rb +27 -0
- data/spec/weathergenerator_spec.rb +63 -0
- data/spec/wind_spec.rb +8 -0
- data/todo.org +3 -2
- metadata +67 -80
- data.tar.gz.sig +0 -1
- data/.gemtest +0 -0
- data/test/rollers/avgroller.rb +0 -7
- data/test/rollers/riggedroller.rb +0 -11
- data/test/test_acceptance.rb +0 -36
- data/test/test_dieroller.rb +0 -30
- data/test/test_greyhawkweather.rb +0 -11
- data/test/test_helper.rb +0 -3
- data/test/test_month.rb +0 -36
- data/test/test_precipitation.rb +0 -26
- data/test/test_precipitation_occurance.rb +0 -93
- data/test/test_singledayweather.rb +0 -61
- data/test/test_sky_conditions.rb +0 -23
- data/test/test_temperature_range.rb +0 -30
- data/test/test_weather_generator.rb +0 -59
- data/test/test_wind.rb +0 -11
- metadata.gz.sig +0 -1
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
greyhawkweather (0.0.7)
|
5
|
+
rangehash (>= 0.0.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
rangehash (0.0.5)
|
12
|
+
rcov (0.9.10)
|
13
|
+
rspec (2.6.0)
|
14
|
+
rspec-core (~> 2.6.0)
|
15
|
+
rspec-expectations (~> 2.6.0)
|
16
|
+
rspec-mocks (~> 2.6.0)
|
17
|
+
rspec-core (2.6.4)
|
18
|
+
rspec-expectations (2.6.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.6.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
greyhawkweather!
|
27
|
+
rcov
|
28
|
+
rspec
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
.rspec
|
1
2
|
History.txt
|
2
3
|
Manifest.txt
|
3
4
|
PostInstall.txt
|
@@ -10,6 +11,7 @@ lib/baselinedata.rb
|
|
10
11
|
lib/greyhawkweather.rb
|
11
12
|
lib/greyhawkweathergenerator.rb
|
12
13
|
lib/month.rb
|
14
|
+
lib/options.rb
|
13
15
|
lib/precipitation.rb
|
14
16
|
lib/precipitationinfo.rb
|
15
17
|
lib/precipitationoccurance.rb
|
@@ -22,18 +24,18 @@ lib/wind.rb
|
|
22
24
|
script/console
|
23
25
|
script/destroy
|
24
26
|
script/generate
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
spec/acceptance_spec.rb
|
28
|
+
spec/dieroller_spec.rb
|
29
|
+
spec/latitude_spec.rb
|
30
|
+
spec/month_spec.rb
|
31
|
+
spec/options_spec.rb
|
32
|
+
spec/precipation_spec.rb
|
33
|
+
spec/precipitation_occurance_spec.rb
|
34
|
+
spec/singledayweather_spec.rb
|
35
|
+
spec/sky_conditions_spec.rb
|
36
|
+
spec/spec_helper.rb
|
37
|
+
spec/temperature_range_spec.rb
|
38
|
+
spec/weathergenerator_spec.rb
|
39
|
+
spec/wind_spec.rb
|
40
|
+
tasks/rspec.rake
|
39
41
|
todo.org
|
data/Rakefile
CHANGED
@@ -1,26 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'hoe'
|
4
|
-
require 'fileutils'
|
5
|
-
require './lib/greyhawkweather'
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
# Hoe.plugin :cucumberfeatures
|
10
|
-
|
11
|
-
# Generate all the Rake tasks
|
12
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec 'greyhawkweather' do
|
14
|
-
self.developer 'Mark Simpson', 'verdammelt@gmail.com'
|
15
|
-
self.post_install_message = 'PostInstall.txt'
|
16
|
-
self.rubyforge_name = self.name
|
17
|
-
self.extra_deps = [['rangehash','>= 0.0.1']]
|
18
|
-
self.extra_rdoc_files = ["README.rdoc"]
|
4
|
+
RSpec::Core::RakeTask.new do |t|
|
5
|
+
t.rspec_opts = ['--format', 'progress']
|
19
6
|
end
|
20
7
|
|
21
|
-
|
22
|
-
|
8
|
+
desc "Run all specs with RCov"
|
9
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
10
|
+
t.rcov = true
|
11
|
+
t.rcov_opts = ['--text-report', '--save', 'coverage.info', '--exclude', 'spec_helper', '--exclude', '^/']
|
12
|
+
end
|
23
13
|
|
24
|
-
|
25
|
-
# remove_task :default
|
26
|
-
# task :default => [:spec, :features]
|
14
|
+
task :default => [:spec]
|
data/bin/greyweathergen
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby -s
|
2
2
|
|
3
3
|
# arbitrary defaults: Weather will be generated for 1st of Planting
|
4
|
-
|
5
4
|
$month ||= 4
|
6
5
|
$numdays ||= 28
|
7
6
|
$terrain ||= "plains"
|
@@ -12,7 +11,12 @@ gem 'rangehash'
|
|
12
11
|
require File.dirname(__FILE__) + '/../lib/greyhawkweather'
|
13
12
|
require 'GreyhawkWeatherGenerator'
|
14
13
|
|
15
|
-
|
14
|
+
options = WeatherGeneratorOptions.new({
|
15
|
+
:month => $month.to_i,
|
16
|
+
:num_days => $numdays.to_i,
|
17
|
+
:terrain => $terrain.to_sym
|
18
|
+
})
|
19
|
+
weather_generator = GreyhawkWeatherGenerator.create_weather_generator options
|
16
20
|
|
17
21
|
i=0
|
18
22
|
weather_generator.days.each do |d|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "greyhawkweather/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "greyhawkweather"
|
7
|
+
s.version = Greyhawkweather::VERSION
|
8
|
+
s.authors = ["Mark Simpson"]
|
9
|
+
s.email = ["verdammelt@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Generates randomized weather based upon the 1983 Greyhawk boxed set.}
|
12
|
+
s.description = <<-EOF
|
13
|
+
Using this gem one can generate randomized weather based upon the
|
14
|
+
rules found in the 1983 boxed set.
|
15
|
+
|
16
|
+
Currently not all features of those rules are applied.
|
17
|
+
|
18
|
+
Future plans include the ability to choose different months and
|
19
|
+
weather chances instead of only those from Greyhawk.
|
20
|
+
EOF
|
21
|
+
|
22
|
+
s.rubyforge_project = "greyhawkweather"
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
|
29
|
+
# specify any dependencies here; for example:
|
30
|
+
s.add_dependency "rangehash", ">=0.0.5"
|
31
|
+
s.add_development_dependency "rspec"
|
32
|
+
s.add_development_dependency "rcov"
|
33
|
+
end
|
data/lib/baselinedata.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'YAML' unless defined? YAML
|
2
|
-
|
3
1
|
require 'temperaturerange'
|
4
2
|
require 'skyconditions'
|
5
3
|
require 'month'
|
@@ -18,7 +16,7 @@ class BaselineData
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def month(monthnum)
|
21
|
-
month_data = @all_data[monthnum -1]
|
19
|
+
month_data = @all_data[monthnum - 1]
|
22
20
|
Month.new(month_data[:temp_range], make_skyconditions(month_data[:sky_conditions]), month_data[:precipitation_chance])
|
23
21
|
end
|
24
22
|
|
data/lib/greyhawkweather.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'baselinedata'
|
2
2
|
require 'util/dieroller'
|
3
3
|
require 'weathergenerator'
|
4
|
+
require 'options'
|
4
5
|
|
5
6
|
class GreyhawkWeatherGenerator
|
6
|
-
def self.create_weather_generator (
|
7
|
+
def self.create_weather_generator (options)
|
7
8
|
WeatherGenerator.new(BaselineData.load("data/baselinedata.yml"),
|
8
|
-
PrecipitationOccurance.load("data/precipitationoccurance.yml"),
|
9
|
-
|
10
|
-
num_days,
|
11
|
-
dieroller,
|
12
|
-
terrain)
|
9
|
+
PrecipitationOccurance.load("data/precipitationoccurance.yml"),
|
10
|
+
options)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
data/lib/options.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'util/dieroller'
|
2
|
+
|
3
|
+
class WeatherGeneratorOptions
|
4
|
+
attr_reader :month
|
5
|
+
attr_reader :num_days
|
6
|
+
attr_reader :dieroller
|
7
|
+
attr_reader :terrain
|
8
|
+
|
9
|
+
def initialize (args = {})
|
10
|
+
@month = args.fetch(:month, 1)
|
11
|
+
@num_days = args.fetch(:num_days, 28)
|
12
|
+
@dieroller = args.fetch(:dieroller, DieRoller.new)
|
13
|
+
@terrain = args.fetch(:terrain, :plains)
|
14
|
+
end
|
15
|
+
end
|
@@ -67,17 +67,21 @@ class PrecipitationOccurance < RangeHash
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def line_above(precip_info)
|
70
|
-
|
70
|
+
current_index = index_of_precip(precip_info) || 0
|
71
|
+
prev_key = sorted_keys[[0,current_index-1].max]
|
71
72
|
self[prev_key]
|
72
73
|
end
|
73
74
|
|
74
75
|
def line_below(precip_info)
|
75
|
-
|
76
|
+
current_index = index_of_precip(precip_info) || sorted_keys.length
|
77
|
+
index = [sorted_keys.length,current_index+1].min
|
78
|
+
next_key = sorted_keys[index]
|
76
79
|
self[next_key]
|
77
80
|
end
|
78
81
|
|
79
82
|
def index_of_precip(precip_info)
|
80
|
-
|
81
|
-
|
83
|
+
pair = select {|k, v| v == precip_info }.first
|
84
|
+
key = pair.first
|
85
|
+
index_of_key = sorted_keys.index(key)
|
82
86
|
end
|
83
87
|
end
|
data/lib/singledayweather.rb
CHANGED
@@ -2,18 +2,20 @@ require 'month'
|
|
2
2
|
require 'precipitationoccurance'
|
3
3
|
require 'precipitationinfo'
|
4
4
|
require 'wind'
|
5
|
+
require 'util/dieroller'
|
5
6
|
|
6
7
|
class SingleDayWeather
|
7
8
|
attr_reader :temperature_range
|
8
9
|
attr_reader :sky_conditions
|
9
10
|
attr_reader :precipitation
|
10
11
|
attr_reader :wind
|
11
|
-
|
12
|
+
|
12
13
|
def initialize (month, dieroller,
|
13
14
|
precipitation_occurance_chart=PrecipitationOccurance.new({ 0..100 => NullPrecipitationInfo.new() }),
|
14
15
|
record_temp=nil,
|
15
|
-
terrain = :plains
|
16
|
-
|
16
|
+
terrain = :plains,
|
17
|
+
latitude = 40)
|
18
|
+
@temperature_range = adjust_for_latitude(month.temp_range(dieroller, record_temp), latitude)
|
17
19
|
@sky_conditions = month.sky_conditions(dieroller)
|
18
20
|
@record_temp = record_temp
|
19
21
|
@precipitation =
|
@@ -25,5 +27,11 @@ class SingleDayWeather
|
|
25
27
|
def inspect
|
26
28
|
"#{@record_temp} #{@temperature_range} #{@sky_conditions} #{@precipitation} #{@wind}"
|
27
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def adjust_for_latitude (range, latitude)
|
33
|
+
adjustment = (latitude-40)*2
|
34
|
+
Range.new(range.first+adjustment, range.last+adjustment)
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
data/lib/skyconditions.rb
CHANGED
@@ -4,7 +4,7 @@ class SkyConditions
|
|
4
4
|
def initialize (clear_range, partly_range, cloudy_range)
|
5
5
|
hash = { clear_range => :clear, partly_range => :partly_cloudy, cloudy_range => :cloudy}
|
6
6
|
@condition_ranges = RangeHash.new(:none)
|
7
|
-
@condition_ranges.merge!
|
7
|
+
@condition_ranges.merge! hash
|
8
8
|
end
|
9
9
|
|
10
10
|
def condition(roller)
|
data/lib/temperaturerange.rb
CHANGED
@@ -15,10 +15,18 @@ class TemperatureRange
|
|
15
15
|
record = make_record_array record
|
16
16
|
|
17
17
|
base = @base
|
18
|
-
base = base + (record
|
19
|
-
base = base - (record
|
18
|
+
base = base + record_adjustment(record, :high, @high_adj)
|
19
|
+
base = base - record_adjustment(record, :low, @low_adj)
|
20
20
|
base
|
21
21
|
end
|
22
|
+
|
23
|
+
def count_records(record, type)
|
24
|
+
record.find_all{|r| r == type}.length
|
25
|
+
end
|
26
|
+
|
27
|
+
def record_adjustment(record, type, adjustment_values)
|
28
|
+
(count_records(record, type) * (adjustment_values[0] + adjustment_values[1]))
|
29
|
+
end
|
22
30
|
|
23
31
|
def make_record_array(record)
|
24
32
|
((record.class == Array) ? record : [record])
|
data/lib/util/dieroller.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class DieRoller
|
2
|
-
def roll(
|
3
|
-
rand(
|
2
|
+
def roll(num_sides, modifier=0)
|
3
|
+
rand(num_sides) + 1 + modifier
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
7
|
class NullDieRoller
|
8
|
-
def roll(
|
8
|
+
def roll(num_sides, modifier=0)
|
9
9
|
-1
|
10
10
|
end
|
11
11
|
end
|
data/lib/weathergenerator.rb
CHANGED
@@ -3,9 +3,11 @@ require 'singledayweather'
|
|
3
3
|
class WeatherGenerator
|
4
4
|
attr_reader :days
|
5
5
|
|
6
|
-
def initialize (baselinedata, precipitation_occurance_chart,
|
7
|
-
month_for_each_day = make_months_for_days_array(baselinedata,
|
8
|
-
@days = month_for_each_day.map
|
6
|
+
def initialize (baselinedata, precipitation_occurance_chart, options)
|
7
|
+
month_for_each_day = make_months_for_days_array(baselinedata, options.month, options.num_days)
|
8
|
+
@days = month_for_each_day.map do |month|
|
9
|
+
make_weather month, options.dieroller, precipitation_occurance_chart, options.terrain
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -31,14 +33,18 @@ class WeatherGenerator
|
|
31
33
|
SingleDayWeather.new(month, dieroller, precipitation_occurance_chart, check_record_high_low(dieroller), terrain)
|
32
34
|
end
|
33
35
|
|
36
|
+
RECORD_HIGH_LOW_RANGES = {
|
37
|
+
1 => [:low, :low, :low],
|
38
|
+
2 => [:low, :low],
|
39
|
+
3..4 => :low,
|
40
|
+
97..98 => :high,
|
41
|
+
99 => [:high, :high],
|
42
|
+
100 => [:high, :high, :high]
|
43
|
+
}
|
44
|
+
|
34
45
|
def check_record_high_low(dieroller)
|
35
46
|
record_high_low_range = RangeHash.new(:normal)
|
36
|
-
record_high_low_range.merge!(
|
37
|
-
2 => [:low, :low],
|
38
|
-
3..4 => :low,
|
39
|
-
97..98 => :high,
|
40
|
-
99 => [:high, :high],
|
41
|
-
100 => [:high, :high, :high]})
|
47
|
+
record_high_low_range.merge!(RECORD_HIGH_LOW_RANGES)
|
42
48
|
record_high_low_range[dieroller.roll(100)]
|
43
49
|
end
|
44
50
|
end
|
data/lib/wind.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
|
2
2
|
class Wind
|
3
|
+
DIRECTIONS = [:N, :NE, :E, :SE, :S, :SW, :W, :NW]
|
4
|
+
|
3
5
|
def initialize(dieroller)
|
4
6
|
@speed = dieroller.roll(20, -1)
|
5
|
-
@direction = [
|
7
|
+
@direction = DIRECTIONS[dieroller.roll(8, -1)]
|
6
8
|
end
|
7
9
|
|
8
10
|
def to_s
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'greyhawkweathergenerator'
|
3
|
+
|
4
|
+
describe "Acceptance Tests" do
|
5
|
+
context GreyhawkWeatherGenerator do
|
6
|
+
let(:roller) do
|
7
|
+
avg_roller_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
context "generates weather with" do
|
11
|
+
let(:options) { WeatherGeneratorOptions.new({:month => 4, :num_days => 1, :dieroller => roller}) }
|
12
|
+
let(:weather) { GreyhawkWeatherGenerator.create_weather_generator(options).days[0] }
|
13
|
+
subject { weather }
|
14
|
+
its(:temperature_range) { should == (44..63) }
|
15
|
+
its(:sky_conditions) { should == :partly_cloudy }
|
16
|
+
|
17
|
+
its(:precipitation) { should be_a_kind_of(Array) }
|
18
|
+
its(:precipitation) { should be }
|
19
|
+
|
20
|
+
describe "precipation" do
|
21
|
+
subject { weather.precipitation[0] }
|
22
|
+
it { should be_a_kind_of(Precipitation) }
|
23
|
+
its(:name) { should == NullPrecipitationInfo.new.name }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should generate multiple days" do
|
28
|
+
num_days = 3
|
29
|
+
options = WeatherGeneratorOptions.new({:dieroller => roller, :num_days => num_days})
|
30
|
+
generator = GreyhawkWeatherGenerator.create_weather_generator(options)
|
31
|
+
|
32
|
+
generator.days.should have(num_days).items
|
33
|
+
generator.days.should_not include(nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates weather for the given month" do
|
37
|
+
options = WeatherGeneratorOptions.new({:dieroller => roller, :month => 8})
|
38
|
+
generator = GreyhawkWeatherGenerator.create_weather_generator(options)
|
39
|
+
weather = generator.days[0]
|
40
|
+
weather.temperature_range.should eq((66..83))
|
41
|
+
weather.sky_conditions.should eq(:partly_cloudy)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "generates weather given a terrain" do
|
45
|
+
roller = rigged_roller_mock 1
|
46
|
+
options = WeatherGeneratorOptions.new({:dieroller => roller, :terrain => :desert})
|
47
|
+
generator = GreyhawkWeatherGenerator.create_weather_generator(options)
|
48
|
+
weather = generator.days[0]
|
49
|
+
weather.precipitation[0].name.should == NullPrecipitationInfo.new().name
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|