Skip to main content
Kinetic Community

Field Values

Field values are stored with an ArsModels Entry like a Ruby hash and can be accessed by field name or field id.  Depending on the field type we use different types of Ruby objects to represent the field values.

Many of the field values can be represented by native ruby classes, these field types are Character, Integer, Decimal, Real, Time, Time of Day, and Date.  For the other field types ArsModels contains classes that better represent the data, these field types are Enum Field Value, Attachment Field Value, Diary Field Value, and Currency Field Value.

Field Value Types

Below is a listing of the field types supported by ArsModels.  For each field type we describe the types of values that are used when reading and writing the field value.

Character
Reading Returns a Ruby String value
Writing

String

entry["Character Field"] = "some value"

Object

When writing to a Character field ArsModels will convert any value given to a string using the objects to_string method.  In the example below we are setting the value to an array, the resulting string value will simply be a concatenation of the array values.

entry["Character Field​"] = ["one", "two", "three"]
Enum
Reading Returns an ArsModels Enum Field Value
Writing

String

When using a string the enumeration option will be selected by name.

entry["Enum Field"] = "Active"

Number

When using a number the enumeration option will be selected by id.

entry["Enum Field"] = 2
Integer
Reading Returns a Ruby Number value
Writing

String

When writing to an Integer field with a string value, an exception will be raised if the string is not in the proper format.

entry["Integer Field"] = "10"

Number

entry["Integer Field"] = 42
Decimal
Reading Returns a Ruby Number value
Writing

String

When writing to a Decimal field with a string value, an exception will be raised if the string is not in the proper format.

entry["Decimal Field"] = "1.3"

Number

entry["Decimal Field"] = 3.14
Real
Reading Returns a Ruby Number value
Writing

String

When writing to a Real field with a string value, an exception will be raised if the string is not in the proper format.

entry["Real Field"] = "1.3"

Number

entry["Real Field"] = 3.14
Date
Reading Returns a Ruby Date value
Writing

String

When using a string to set a Date field value in ArsModels the supported format is YYYY-MM-DD.  An exception will be raised if the string does not match this pattern.

entry["Date Field"] = "2013-05-06"

Number

When using a number to set a Date field value in ArsModels the number is the Julian date.  In the example below the number 2456414 represents the Julian date for 1 May 2013.

entry["Date Field"] = 2456414

Date

entry["Date Field"] = Date.parse("2013-05-01")
Time
Reading Returns a Ruby Time value
Writing

String

When using a string to set a Time value in ArsModels there are multiple supported formats (shown below). Note that in all the examples listed below the "T" character can be replaced with space.  An exception will be raised if the string does not match these patterns.

  • 2013-01-31T16:45:35Z
  • 2013-01-31T16:45:35
  • 2013-01-31T16:45:35-0600
  • 2013-01-31T16:45:35-06:00
  • 2013-01-31T16:45:35-06
entry["Date/Time Field"] = "2013-01-31T16:45:35Z"

Number

When using a number to set a Time field value in ArsModels the number is the Epoch timestamp.  In the example below the number 1367853849 represents the Epoch timestamp for 6 May 2013 19:59:44 GMT.

entry["Date/Time Field"] = 1367853849

Time

entry["Date/Time Field"] = Time.parse("2013-05-06 05:45:35")
Time Of Day
Reading Returns a Ruby Time value
Writing

String

When using a string to set a Time of day value in ArsModels the supported format is HH:MM:SS.  An exception will be raised if the string does not match this pattern.

entry["Time Field"] = "05:45:35"

Number

When using a number to set a Time of day field value in ArsModels the number is the number of seconds since midnight.  In the example below the number 20735 represents 05:45:35.

entry["Time Field"] = 20735

Time

entry["Time Field"] = Time.parse("05:45:35")
Attachment
Reading Returns an ArsModels Attachment Field Value
Writing

String

When using a string to set an Attachment value in ArsModels the supported format is the base64 encoded content followed by a semi-colon, then the content size followed by another semi-colon, then finally the file name.  An exception will be raised if the string does not match this pattern.

entry["Attachment Field"] = "VGVzdCE=;5;attachment.txt"

File

entry["Attachment Field"] = File.new("attachment.txt")

ArsModels Attachment Field Value

entry["Attachment Field"] = ArsModels::FieldValues::AttachmentFieldValue.new(
  :name => "attachment.txt",
  :size => 5,
  :content => "Test!"
)
Diary
Reading Returns an ArsModels Diary Field Value
Writing

String

entry["Diary Field"] = "This is a new diary entry."

Note that you cannot write a null value to a diary field.  If nil or an empty string is assigned a diary entry will not be created for that modification.

Currency
Reading Returns an ArsModels Currency Field Value
Writing

Hash

entry["Currency Field"] = {
  :value    => 9.99,
  :currency => "USD"
}