Class: Jirarest2Field::HashField
- Defined in:
- lib/jirarest2/field.rb
Overview
A Field that presents its value in an hash that has additional information (“name”,“id”,“key”,“value”)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ String
readonly
The key element for the answers - It should not be needed - but it’s easer on the checks if it’s exposed.
Attributes inherited from Field
#allowed_values, #id, #name, #raw_value, #readonly, #required
Instance Method Summary collapse
-
#initialize(id, name, args) ⇒ HashField
constructor
A new instance of HashField.
-
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server.
-
#to_j(value = @value) ⇒ Hash
Representation to be used for json and jira.
-
#to_j_inner(value = @value) ⇒ Hash
Representation to be used for json and jira without the fieldID.
Methods inherited from Field
#createmeta, #value, #value=, #value_allowed?
Constructor Details
#initialize(id, name, args) ⇒ HashField
Returns a new instance of HashField.
271 272 273 274 275 276 |
# File 'lib/jirarest2/field.rb', line 271 def initialize(id,name,args) @key ||= nil # Trying to initialize without overwriting something that might come from the subclass @key = args[:key].downcase if ( ! args[:createmeta] && args[:key]) super raise Jirarest2::HashKeyMissingException, "HashTypes like in #{id} alway require a key!" if @key.nil? end |
Instance Attribute Details
#key ⇒ String (readonly)
The key element for the answers - It should not be needed - but it’s easer on the checks if it’s exposed
264 265 266 |
# File 'lib/jirarest2/field.rb', line 264 def key @key end |
Instance Method Details
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server
291 292 293 294 295 296 297 298 |
# File 'lib/jirarest2/field.rb', line 291 def parse_value(jvalue) super if jvalue.nil? then @value = nil else @value = jvalue[key] end end |
#to_j(value = @value) ⇒ Hash
Representation to be used for json and jira
280 281 282 283 284 285 286 287 |
# File 'lib/jirarest2/field.rb', line 280 def to_j(value = @value) if value.nil? then super(nil) else valuehash = {@key => value} super(valuehash) end end |
#to_j_inner(value = @value) ⇒ Hash
Representation to be used for json and jira without the fieldID
302 303 304 305 306 307 308 309 |
# File 'lib/jirarest2/field.rb', line 302 def to_j_inner(value = @value) if value.nil? then super(nil) else valuehash = {@key => value} super(valuehash) end end |