diaspora-cluster-creator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ cluster.png
19
+ cluster.dot
data/README.md CHANGED
@@ -7,6 +7,8 @@ fast unit tests.
7
7
 
8
8
  ## Installation
9
9
 
10
+ You will need to install [Graphviz](http://graphviz.org)
11
+
10
12
  Add this line to your application's Gemfile:
11
13
 
12
14
  gem 'diaspora-cluster-creator'
@@ -21,7 +23,21 @@ Or install it yourself as:
21
23
 
22
24
  ## Usage
23
25
 
26
+ Once installed you can ask diaspora-cluster for help
27
+
28
+ $ diaspora-cluster -h
29
+
30
+ Or request the defaults
31
+
32
+ $ diaspora-cluster
33
+
34
+ Or you can specify names
35
+
36
+ $ diaspora-cluster names="Sparta [T2 E1 R3], Athens [T-2], Corinth [R3 T2 E1], Ephesus, Rhodes [T4]"
37
+
38
+ Or perhaps you prefer a PNG
24
39
 
40
+ $ diaspora-cluster filename=output.png names="Sparta [T2 E1 R3], Athens [T-2], Corinth [R3 T2 E1], Ephesus, Rhodes [T4]"
25
41
 
26
42
  ## Contributing
27
43
 
@@ -3,9 +3,4 @@ Feature: Cluster creation
3
3
  Scenario: Cluster creation
4
4
  When I request a new cluster with 5 star systems
5
5
  Then the output should have 5 nodes
6
- And the output should have at least 4 edges
7
-
8
- Scenario: Named systems
9
- When I create a new cluster with systems "Foo", "Bar", "Baz"
10
- Then the graph should have nodes "Foo", "Bar", "Baz"
11
- And the graph should have edges between "Foo", "Bar", "Baz"
6
+ And the output should have at least 4 edges
@@ -4,4 +4,10 @@ Scenario: Star System Creation
4
4
  When I create a Star System
5
5
  Then it should have a technology rating
6
6
  And it should have a resources rating
7
- And it should have a environment rating
7
+ And it should have a environment rating
8
+
9
+ Scenario: Named Star System Creation
10
+ When I create a Star System with name "Sparta [T1 E-2 R3]"
11
+ Then it should have a technology rating of 1
12
+ And it should have a resources rating of 3
13
+ And it should have a environment rating of -2
@@ -2,7 +2,15 @@ When /^I create a Star System$/ do
2
2
  current_star_system
3
3
  end
4
4
 
5
+ When /^I create a Star System with (?:the )?name "([^"]*)"$/ do |name|
6
+ set_current_star_system(name)
7
+ end
8
+
5
9
  Then /^it should have an? (#{CAPTURE_SYSTEM_ATTRIBUTE}) rating$/ do |system_attribute|
6
10
  current_star_system.send(system_attribute).must_be :<=, 4
7
11
  current_star_system.send(system_attribute).must_be :>=, -4
12
+ end
13
+
14
+ Then /^it should have an? (#{CAPTURE_SYSTEM_ATTRIBUTE}) rating of (#{CAPTURE_INTEGER})$/ do |system_attribute, rating|
15
+ current_star_system.send(system_attribute).must_equal rating
8
16
  end
@@ -15,6 +15,11 @@ module KnowsTheDomain
15
15
  def current_star_system
16
16
  @current_star_system ||= StarSystem.new(current_cluster, 1)
17
17
  end
18
+
19
+ def set_current_star_system(value)
20
+ @current_star_system = StarSystem.new(current_cluster, value)
21
+ end
22
+
18
23
  def current_graph
19
24
  @current_graph ||= Graph.new(current_cluster)
20
25
  end
@@ -12,8 +12,8 @@ module Diaspora
12
12
  end
13
13
  @@rolled_attributes
14
14
  end
15
- def self.rolled_attribute(attribute_name)
16
- rolled_attributes << attribute_name
15
+ def self.rolled_attribute(attribute_name, abbreviation = nil)
16
+ rolled_attributes << attribute_name.to_s
17
17
  define_method(attribute_name) do
18
18
  instance_variable_get("@#{attribute_name}") || instance_variable_set("@#{attribute_name}", dice.roll)
19
19
  instance_variable_get("@#{attribute_name}")
@@ -36,12 +36,12 @@ module Diaspora
36
36
  attr_reader :context, :name
37
37
  def initialize(context, name)
38
38
  @context = context
39
- @name = name
39
+ set_name(name.to_s)
40
40
  end
41
41
 
42
- rolled_attribute :technology
43
- rolled_attribute :resources
44
- rolled_attribute :environment
42
+ rolled_attribute :technology, :t
43
+ rolled_attribute :resources, :r
44
+ rolled_attribute :environment, :e
45
45
 
46
46
  include Comparable
47
47
  def <=>(other)
@@ -59,6 +59,21 @@ module Diaspora
59
59
  def label
60
60
  "#{name}\nT#{technology} R#{resources} E#{environment}"
61
61
  end
62
+
63
+ protected
64
+ def set_name(name_with_attribtes)
65
+ name, options = name_with_attribtes.strip.split(/ *\[/)
66
+ @name = name
67
+ if options
68
+ options.sub(/\]$/,'').split.collect(&:strip).each do |option|
69
+ original, attribute_prefix, value = option.match(/(\w) *(-?\d)/).to_a
70
+ if attribute_name = self.class.rolled_attributes.detect {|roled_attribute| roled_attribute =~ /^#{attribute_prefix}/i}
71
+ send("#{attribute_name}=",value)
72
+ end
73
+ end
74
+ end
75
+ @name
76
+ end
62
77
  end
63
78
  end
64
79
  end
@@ -1,7 +1,7 @@
1
1
  module Diaspora
2
2
  module Cluster
3
3
  module Creator
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -3,14 +3,28 @@ require 'star_system'
3
3
 
4
4
  describe StarSystem do
5
5
  subject { StarSystem.new( Object.new, 1 ) }
6
-
6
+
7
+ describe '#initialize with one attribute' do
8
+ subject { StarSystem.new(Object.new, "Sparta [T1 E-4]") }
9
+ it 'should have an extracted name' do
10
+ subject.name.must_equal 'Sparta'
11
+ end
12
+ it 'should have an preset attribute' do
13
+ with_loaded_dice(0, subject) do
14
+ subject.resources.must_equal 0
15
+ subject.technology.must_equal 1
16
+ subject.environment.must_equal -4
17
+ end
18
+ end
19
+ end
20
+
7
21
  describe '#technology=' do
8
22
  it 'should be overridable' do
9
23
  subject.technology = 3
10
24
  subject.technology.must_equal 3
11
25
  end
12
26
  end
13
-
27
+
14
28
  describe '#technology' do
15
29
  it 'should be randomly rolled' do
16
30
  with_loaded_dice(1, subject) do
@@ -34,7 +48,7 @@ describe StarSystem do
34
48
  end
35
49
  end
36
50
  end
37
-
51
+
38
52
  describe '#<=>' do
39
53
  it 'should be comparable to another star system' do
40
54
  @system_a = StarSystem.new('', 1)
@@ -46,13 +60,13 @@ describe StarSystem do
46
60
  end
47
61
  end
48
62
  end
49
-
63
+
50
64
  describe '.guarantee!' do
51
65
  it 'should adjust technology rating without altering the sort order' do
52
66
  @system_a = StarSystem.new('', 1)
53
67
  @system_b = StarSystem.new('', 2)
54
68
  @system_c = StarSystem.new('', 3)
55
- order =
69
+ order =
56
70
  with_loaded_dice(1, @system_a) do
57
71
  with_loaded_dice(0, @system_b) do
58
72
  with_loaded_dice(-1, @system_c) do
@@ -71,7 +85,7 @@ describe StarSystem do
71
85
  @system_a = StarSystem.new('', 1)
72
86
  @system_b = StarSystem.new('', 2)
73
87
  @system_c = StarSystem.new('', 3)
74
- order =
88
+ order =
75
89
  with_loaded_dice(2, @system_a) do
76
90
  with_loaded_dice(0, @system_b) do
77
91
  with_loaded_dice(-1, @system_c) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora-cluster-creator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
16
- requirement: &2156617540 !ruby/object:Gem::Requirement
16
+ requirement: &2152337300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156617540
24
+ version_requirements: *2152337300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2156617120 !ruby/object:Gem::Requirement
27
+ requirement: &2152336840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156617120
35
+ version_requirements: *2152336840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &2156616680 !ruby/object:Gem::Requirement
38
+ requirement: &2152336300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156616680
46
+ version_requirements: *2152336300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2156616040 !ruby/object:Gem::Requirement
49
+ requirement: &2152335700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156616040
57
+ version_requirements: *2152335700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-minitest
60
- requirement: &2156615380 !ruby/object:Gem::Requirement
60
+ requirement: &2152335000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2156615380
68
+ version_requirements: *2152335000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-bundler
71
- requirement: &2156614900 !ruby/object:Gem::Requirement
71
+ requirement: &2152333700 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2156614900
79
+ version_requirements: *2152333700
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-cucumber
82
- requirement: &2156614460 !ruby/object:Gem::Requirement
82
+ requirement: &2152332980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2156614460
90
+ version_requirements: *2152332980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: growl
93
- requirement: &2156613960 !ruby/object:Gem::Requirement
93
+ requirement: &2152332540 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2156613960
101
+ version_requirements: *2152332540
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ruby-graphviz
104
- requirement: &2156613480 !ruby/object:Gem::Requirement
104
+ requirement: &2152331640 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2156613480
112
+ version_requirements: *2152331640
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: main
115
- requirement: &2156613040 !ruby/object:Gem::Requirement
115
+ requirement: &2152330880 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2156613040
123
+ version_requirements: *2152330880
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: dependency_injector
126
- requirement: &2156612580 !ruby/object:Gem::Requirement
126
+ requirement: &2152330440 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *2156612580
134
+ version_requirements: *2152330440
135
135
  description: Command-line utility to create Diaspora cluster
136
136
  email:
137
137
  - jeremy.n.friesen@gmail.com