Copyright © 2014 by mTLD Top Level Domain Limited. All rights reserved.
Portions copyright © 2008 by Argo Interactive Limited.
Portions copyright © 2008 by Nokia Inc.
Portions copyright © 2008 by Telecom Italia Mobile S.p.A.
Portions copyright © 2008 by Volantis Systems Limited.
Portions copyright © 2002-2008 by Andreas Staeding.
Portions copyright © 2008 by Zandan.
dotMobi
Contains a property value and data type id. The value can be fetched as a generic Object or one of the convenience to_X methods can be used to get the value in a specific type.
Creates a new Property with a value and data type
value
The value to store
data_type
Byte or char that represents the data type of the value to
store
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 31 def initialize value, data_type # Conversion to prevent characters represented by their ASCII code. if data_type.kind_of?String # Save the data type Id case data_type.to_sym when :b @data_type_id = DataType::BOOLEAN when :i @data_type_id = DataType::INTEGER when :s @data_type_id = DataType::STRING when :d @data_type_id = DataType::DOUBLE else @data_type_id = DataType::UNKNOWN end elsif data_type.kind_of?Fixnum @data_type_id = data_type end # Save the value @value = value # Save the data type name in a private variable @data_type_name = DataType.name @data_type_id end
Compare two instances of this class. If both have equal values and data type then returns true.
return
Boolean value based on whether both objects are equal or not.
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 124 def ==(property) if property.nil? || !property.kind_of?(Property) || @data_type_id != property.data_type_id || @value != property.value return false end return true end
Get data type name.
return
String with the data type name
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 66 def data_type return @data_type_name end
Get the value of the property as a boolean.
return
The TrueClass/FalseClass value of the property
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 72 def to_b if @data_type_id != DataType::BOOLEAN raise Mobi::Mtld::Da::Exception::IncorrectPropertyTypeException, 'Property is not convertible to a boolean.' end return !@value.nil? && @value != 'false' && @value.to_s != '0' end
Get the value of the property as an integer.
return
The integer value of the property
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 82 def to_i type = @data_type_id if type == DataType::BYTE || type == DataType::SHORT || type == DataType::INTEGER return @value.to_i end raise Mobi::Mtld::Da::Exception::IncorrectPropertyTypeException, 'Property is not convertible to an int.' end
Get the value of the property as string. If a property has multiple possible values then the values are concatenated with a comma.
return
The string value of the property
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 106 def to_s if @value.kind_of?(Array) return @value.join(',') end if @data_type_id == DataType::BOOLEAN value = @value.to_s if value == "0" return "false" else return "true" end end return @value.to_s end
Gets a set of possible values for this property. This is typically only used when it is known that a given property name can have multiple possible values. All items in the set will have the same data type.
return
The array value of the property
# File ../../device_api/trunk/ruby/src/lib/property.rb, line 96 def to_set if @value.kind_of?(Array) return @value end return [@value] end