Class: Jirarest2Field::DateField

Inherits:
Field
  • Object
show all
Defined in:
lib/jirarest2/field.rb

Overview

A simple Date field.

Direct Known Subclasses

DateTimeField

Instance Attribute Summary

Attributes inherited from Field

#allowed_values, #id, #name, #raw_value, #readonly, #required

Instance Method Summary collapse

Methods inherited from Field

#createmeta, #initialize, #value_allowed?

Constructor Details

This class inherits a constructor from Jirarest2Field::Field

Instance Method Details

#parse_value(jvalue) ⇒ Object

Parse the value of this field as sent by the server



197
198
199
200
# File 'lib/jirarest2/field.rb', line 197

def parse_value(jvalue)
  super
  @value = Date.parse(jvalue)
end

#to_j(value = @value) ⇒ Hash

Representation to be used for json and jira

Returns:

  • (Hash)


187
188
189
190
191
192
193
# File 'lib/jirarest2/field.rb', line 187

def to_j(value = @value)
  if value.nil? then
    super(nil)
  else
    super(value.to_s)
  end
end

#to_j_innerHash

Representation to be used for json and jira without the fieldId

Returns:

  • (Hash)


204
205
206
207
208
209
210
# File 'lib/jirarest2/field.rb', line 204

def to_j_inner
  if @value.nil? then
    super(nil)
  else
    super(@value.to_s)
  end
end

#value(raw = false) ⇒ String, Date

Get the value

Parameters:

  • raw (Boolean) (defaults to: false)

    true returns a date Object, false a String

Returns:

  • (String)

    if raw is false (default)

  • (Date)

    if raw is true



177
178
179
180
181
182
183
# File 'lib/jirarest2/field.rb', line 177

def value(raw = false)
  if raw then
    super
  else
    return @value.to_s
  end
end

#value=(content) ⇒ Object

Set the value

Parameters:

  • content (String)

    The date in a string representation (Either [YY]YY-[M]M-D or [D]D.M.YYYY or YY.[M]M.D See Date.parse)



168
169
170
171
# File 'lib/jirarest2/field.rb', line 168

def value=(content)
  value = Date.parse(content)
  @value = value if value_allowed?(value)
end