grimoire 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef5df1a91ba2a0ba8d102c0566e2eccca125678c
4
- data.tar.gz: 7f2faf3d48426e22fee9ddf77d2c7845d1897071
3
+ metadata.gz: 200bc22b954a33f6ec11d2a41403afafacc3fe35
4
+ data.tar.gz: e2ebba16137affccdf764c24c08132f8668bc6ab
5
5
  SHA512:
6
- metadata.gz: 67788092dff047186519fff5efe33869c3395bda3769f49de24dca62d8a5e2a466d11278fbd770ed0cb14b212f782321a5c90c37ff8c9e6f555bfb68201a50cf
7
- data.tar.gz: 548afdfb3c061bb89591113404c438e97d9ecf4ed7cb74b4cf5b843c4c2a820e998218bb3e3f2b72fbc5a262cf99c0ed61168f9f354cb7abd6c3ab76fb3f6125
6
+ metadata.gz: a4dbcf9162fe2846c739bb71fd1a9d50e87a7f843841663b0c7878917dbbf2dbab2a6ef004498543a3d07ba03c14806e714da846f15e523918c9f9fb434f5516
7
+ data.tar.gz: fa8a7d53d999489bf596f3ffbf1f77d5fd04ee68b3b5e3e236aab6dc2df230f55d75f4100cca5e9a6e1d3c4d00c703e813052a1cf87cd64e5042d771be42aa9d
data/CHANGELOG.md CHANGED
@@ -1,2 +1,7 @@
1
+ # v0.1.2
2
+ * Add JSON serialization support to utility instances
3
+ * Add abstract for unit scoring
4
+ * Populate queues in single push
5
+
1
6
  # v0.1.0
2
7
  * Initial commit
data/lib/grimoire.rb CHANGED
@@ -17,6 +17,7 @@ module Grimoire
17
17
  autoload :Solver, 'grimoire/solver'
18
18
  autoload :System, 'grimoire/system'
19
19
  autoload :Unit, 'grimoire/unit'
20
+ autoload :UnitScoreKeeper, 'grimoire/unit_score_keeper'
20
21
  autoload :Utility, 'grimoire/utility'
21
22
 
22
23
  end
@@ -11,6 +11,7 @@ module Grimoire
11
11
 
12
12
  attribute :requirements, RequirementList, :required => true
13
13
  attribute :system, System, :required => true
14
+ attribute :score_keeper, UnitScoreKeeper
14
15
 
15
16
  # @return [System] subset of full system based on requirements
16
17
  attr_reader :world
@@ -60,9 +61,11 @@ module Grimoire
60
61
  # @param units [Array<Unit>]
61
62
  # @return [Bogo::PriorityQueue]
62
63
  def populate_queue(p_queue, units)
63
- units.each_with_index do |unit, index|
64
- p_queue.push(unit, score_unit(unit, index))
64
+ i = 0
65
+ units = units.map do |unit|
66
+ [unit, score_unit(unit, i += 1)]
65
67
  end
68
+ p_queue.multi_push(units)
66
69
  p_queue
67
70
  end
68
71
 
@@ -70,9 +73,13 @@ module Grimoire
70
73
  #
71
74
  # @param unit [Unit]
72
75
  # @param score [Integer] current score
73
- # @return [Integer] score
76
+ # @return [Numeric] score
74
77
  def score_unit(unit, score)
75
- score
78
+ if(score_keeper)
79
+ score_keeper.score_for(unit) || score
80
+ else
81
+ score
82
+ end
76
83
  end
77
84
 
78
85
  # Repopulate the given queue
@@ -0,0 +1,15 @@
1
+ require 'grimoire'
2
+
3
+ module Grimoire
4
+ class UnitScoreKeeper < Utility
5
+
6
+ # Provide score for given unit
7
+ #
8
+ # @param unit [Unit]
9
+ # @return [Numeric]
10
+ def score_for(unit)
11
+ raise NotImplementedError.new 'No scoring has been defined'
12
+ end
13
+
14
+ end
15
+ end
@@ -16,6 +16,10 @@ module Grimoire
16
16
  load_data(args)
17
17
  end
18
18
 
19
+ # @return [String] JSON serialized
20
+ def to_json(*args)
21
+ MultiJson.dump(data, *args)
22
+ end
19
23
  end
20
24
 
21
25
  end
@@ -1,4 +1,4 @@
1
1
  module Grimoire
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.0')
3
+ VERSION = Gem::Version.new('0.1.2')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grimoire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo
@@ -70,6 +70,7 @@ files:
70
70
  - lib/grimoire/solver.rb
71
71
  - lib/grimoire/system.rb
72
72
  - lib/grimoire/unit.rb
73
+ - lib/grimoire/unit_score_keeper.rb
73
74
  - lib/grimoire/utility.rb
74
75
  - lib/grimoire/version.rb
75
76
  homepage: https://github.com/spox/grimoire