clear-election-sdk 0.0.1 → 0.1.0

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: 35f1b77def83bb18cbc429b636a9bdcd1683ea30
4
- data.tar.gz: 9f6136cec7c9af255eb48b92a36af5d16050957c
3
+ metadata.gz: 9f7ae5f65a76e6af6f6be8c8cc86fb7bd506d309
4
+ data.tar.gz: 3a7bf5ab2eb535819a4b734cec6b660664cc9e6b
5
5
  SHA512:
6
- metadata.gz: 0200ddc2529f35c99c1b47e165fa3653ee70904208f3f2e3da9416c8fdf0e4473d268e4d798411582c36e965de0dba497c220851a50dee3b7bf7182a43d53d43
7
- data.tar.gz: c49ca30e6358a306db28619e82d4cf4b50061ae1785fb7b8b2434fafd0ea7d697a3077773560ea40bbef8f2bc9ab439defc9b722ff2673efbaa0b0c7701056dc
6
+ metadata.gz: 93536a99c4d22e7969b0b0f9a9623e38ccd87b78a14e2ebab6d79313b21c753e845c38dd6e90f679c3d58e587c7595cadfb9aeb0b3b7fefdcd3e707fc46acb4b
7
+ data.tar.gz: 9320bacb18a27ecf46d2d5d2a83b1fa8e34a3014a92065231040e230c632a2be6473b7ab9d45feac0ceb56c732ad9f94663dbe7aba4b882392c3bd7ce8fa7510
@@ -4,13 +4,13 @@ module ClearElection
4
4
 
5
5
  SCHEMA_VERSION = 0.0
6
6
 
7
- attr_reader :signin, :booth, :pollsOpen, :pollsClose, :contests, :uri
7
+ attr_reader :signin, :booth, :pollsOpen, :pollsClose, :contests, :uri, :voters, :ballots
8
8
 
9
9
  def self.schema
10
10
  ClearElection::Schema.election(version: SCHEMA_VERSION)
11
11
  end
12
12
 
13
- def initialize(name:, signin:, booth:, contests:, pollsOpen:, pollsClose:, uri:nil)
13
+ def initialize(name:, signin:, booth:, contests:, pollsOpen:, pollsClose:, uri:nil, voters:nil, ballots:nil)
14
14
  @name = name
15
15
  @signin = signin
16
16
  @booth = booth
@@ -18,6 +18,8 @@ module ClearElection
18
18
  @pollsOpen = pollsOpen
19
19
  @pollsClose = pollsClose
20
20
  @uri = uri
21
+ @voters = voters || []
22
+ @ballots = ballots || []
21
23
  end
22
24
 
23
25
  def self.from_json(data, uri: nil)
@@ -29,13 +31,15 @@ module ClearElection
29
31
  contests: data["contests"].map {|data| Contest.from_json(data) },
30
32
  pollsOpen: DateTime.rfc3339(data["schedule"]["pollsOpen"]),
31
33
  pollsClose: DateTime.rfc3339(data["schedule"]["pollsClose"]),
32
- uri: uri
34
+ uri: uri,
35
+ voters: data["returns"]["voters"],
36
+ ballots: data["returns"]["ballots"].map { |data| Ballot.from_json(data) }
33
37
  )
34
38
  end
35
39
 
36
40
  def as_json()
37
41
  data = {
38
- "version" => "0.0",
42
+ "clearelection" => "0.0",
39
43
  "name" => @name,
40
44
  "agents" => {
41
45
  "signin" => @signin.as_json,
@@ -47,10 +51,19 @@ module ClearElection
47
51
  },
48
52
  "contests" => @contests.map(&:as_json)
49
53
  }
54
+ data["returns"] = {
55
+ "voters" => @voters,
56
+ "ballots" => @ballots.map(&:as_json)
57
+ }
50
58
  JSON::Validator.validate!(Election.schema, data)
51
59
  data
52
60
  end
53
61
 
62
+ def set_returns(voters:, ballots:)
63
+ @voters = voters
64
+ @ballots = ballots
65
+ end
66
+
54
67
  # utilities
55
68
  def polls_have_not_opened?
56
69
  DateTime.now < pollsOpen
@@ -18,7 +18,8 @@ module ClearElection
18
18
  booth: nil,
19
19
  pollsOpen: nil,
20
20
  pollsClose: nil,
21
- writeIn: true
21
+ writeIn: true,
22
+ returns: false
22
23
  )
23
24
  one_month = 60*60*24*30
24
25
  Election.new(
@@ -31,7 +32,14 @@ module ClearElection
31
32
  Factory.contest(ranked: true, multiplicity: 3, writeIn: writeIn, ncandidates: 3),
32
33
  Factory.contest(ncandidates: 2)
33
34
  ]
34
- )
35
+ ).tap { |election|
36
+ if returns
37
+ election.set_returns(
38
+ voters: 10.times.map{ { "name" => seq("Voter") } }.sort_by { |v| v[:name] },
39
+ ballots: 10.times.map{ Factory.ballot(election) }.sort
40
+ )
41
+ end
42
+ }
35
43
  end
36
44
 
37
45
  def self.contest(ranked: nil, multiplicity: nil, writeIn: nil, ncandidates: 3)
@@ -1,3 +1,3 @@
1
1
  module ClearElection
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -4,7 +4,7 @@
4
4
  "description": "ClearElection Election definition, v0.0",
5
5
  "type": "object",
6
6
  "properties": {
7
- "version": { "enum": ["0.0"] },
7
+ "clearelection": { "enum": ["0.0"] },
8
8
  "name": { "type": "string" },
9
9
  "agents": {
10
10
  "type": "object",
@@ -44,9 +44,21 @@
44
44
  },
45
45
  "required": ["contestId", "name", "candidates"]
46
46
  }
47
+ },
48
+ "results": {
49
+ "type": "object",
50
+ "properties": {
51
+ "ballots": {
52
+ "type": "array",
53
+ "items": { "$ref": "#/definitions/ballot" }
54
+ },
55
+ "voters": {
56
+ "type": "object"
57
+ }
58
+ }
47
59
  }
48
60
  },
49
- "required": ["version", "name", "agents", "schedule", "contests"],
61
+ "required": ["clearelection", "name", "schedule", "contests"],
50
62
  "definitions": {
51
63
  "agent": {
52
64
  "type": "object",
@@ -54,7 +66,8 @@
54
66
  "uri": { "type": "string", "format": "uri" }
55
67
  },
56
68
  "required": ["uri"]
57
- }
69
+ },
70
+ "ballot": { "$ref": "file:schemas/ballot-0.0.schema.json" }
58
71
  }
59
72
  }
60
73
 
@@ -46,4 +46,23 @@ describe ClearElection::Election do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe "json" do
51
+
52
+ it "makes round trip without returns" do
53
+ roundtrip ClearElection::Factory.election(returns: false)
54
+ end
55
+
56
+ it "makes round trip with returns" do
57
+ roundtrip ClearElection::Factory.election(returns: true)
58
+ end
59
+
60
+ def roundtrip(election)
61
+ original_json = JSON.generate election.as_json
62
+ final_json = JSON.generate ClearElection::Election.from_json(JSON.parse original_json).as_json
63
+ expect(final_json).to eq original_json
64
+ end
65
+
66
+ end
67
+
49
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clear-election-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday