Class: ClearElection::Ballot::Choice

Inherits:
Object
  • Object
show all
Defined in:
lib/clear-election-sdk/ballot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(candidateId:, rank: nil) ⇒ Choice

Returns a new instance of Choice.



125
126
127
128
# File 'lib/clear-election-sdk/ballot.rb', line 125

def initialize(candidateId:, rank: nil)
  @candidateId = candidateId
  @rank = rank
end

Instance Attribute Details

#candidateIdObject (readonly)

Returns the value of attribute candidateId.



124
125
126
# File 'lib/clear-election-sdk/ballot.rb', line 124

def candidateId
  @candidateId
end

#rankObject (readonly)

Returns the value of attribute rank.



124
125
126
# File 'lib/clear-election-sdk/ballot.rb', line 124

def rank
  @rank
end

Class Method Details

.from_json(data, rank: nil) ⇒ Object



142
143
144
145
# File 'lib/clear-election-sdk/ballot.rb', line 142

def self.from_json(data, rank: nil)
  self.new(candidateId: data["candidateId"],
           rank: rank)
end

Instance Method Details

#abstain?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/clear-election-sdk/ballot.rb', line 134

def abstain?
  @candidateId == "ABSTAIN"
end

#as_jsonObject



147
148
149
150
151
# File 'lib/clear-election-sdk/ballot.rb', line 147

def as_json
  {
    "candidateId" => @candidateId
  }
end

#candidate?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/clear-election-sdk/ballot.rb', line 138

def candidate?
  not (writeIn? or abstain?)
end

#writeIn?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/clear-election-sdk/ballot.rb', line 130

def writeIn?
  @candidateId.start_with?("WRITEIN:")
end