class Comet::StoredObject
StoredObject
is a typed class wrapper around the underlying Comet
Server API data structure.
Attributes
@type [String] display_name
@type [Number] end_time
@type [String] from
@type [Boolean] has_attachments
@type [String] item_class
@type [Number] modify_time
@type [String] name
@type [Number] received_date_time
@type [Number] recursive_bytes
@type [Boolean] recursive_count_known
@type [Number] recursive_files
@type [Number] recursive_folders
@type [Number] size
@type [Number] start_time
@type [String] subtree
@type [String] to
@type [String] type
@type [Hash] Hidden storage to preserve future properties for non-destructive roundtrip operations
Public Class Methods
# File lib/comet/models/stored_object.rb, line 71 def initialize clear end
Public Instance Methods
# File lib/comet/models/stored_object.rb, line 75 def clear @name = '' @modify_time = 0 @type = '' @subtree = '' @size = 0 @display_name = '' @item_class = '' @from = '' @to = '' @received_date_time = 0 @start_time = 0 @end_time = 0 @recursive_files = 0 @recursive_bytes = 0 @recursive_folders = 0 @unknown_json_fields = {} end
@param [Hash] obj The complete object as a Ruby hash
# File lib/comet/models/stored_object.rb, line 102 def from_hash(obj) raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash obj.each do |k, v| case k when 'name' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @name = v when 'mtime' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @modify_time = v when 'type' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @type = v when 'subtree' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @subtree = v when 'size' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @size = v when 'dname' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @display_name = v when 'itemClass' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @item_class = v when 'from' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @from = v when 'to' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @to = v when 'rtime' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @received_date_time = v when 'has_attachments' @has_attachments = v when 'stime' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @start_time = v when 'etime' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @end_time = v when 'r' @recursive_count_known = v when 'f' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @recursive_files = v when 'b' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @recursive_bytes = v when 'd' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @recursive_folders = v else @unknown_json_fields[k] = v end end end
@param [String] json_string The complete object in JSON format
# File lib/comet/models/stored_object.rb, line 95 def from_json(json_string) raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String from_hash(JSON.parse(json_string)) end
@return [Hash] The complete object as a Ruby hash
# File lib/comet/models/stored_object.rb, line 228 def to_h to_hash end
@return [Hash] The complete object as a Ruby hash
# File lib/comet/models/stored_object.rb, line 178 def to_hash ret = {} ret['name'] = @name ret['mtime'] = @modify_time ret['type'] = @type ret['subtree'] = @subtree ret['size'] = @size unless @display_name.nil? ret['dname'] = @display_name end unless @item_class.nil? ret['itemClass'] = @item_class end unless @from.nil? ret['from'] = @from end unless @to.nil? ret['to'] = @to end unless @received_date_time.nil? ret['rtime'] = @received_date_time end unless @has_attachments.nil? ret['has_attachments'] = @has_attachments end unless @start_time.nil? ret['stime'] = @start_time end unless @end_time.nil? ret['etime'] = @end_time end unless @recursive_count_known.nil? ret['r'] = @recursive_count_known end unless @recursive_files.nil? ret['f'] = @recursive_files end unless @recursive_bytes.nil? ret['b'] = @recursive_bytes end unless @recursive_folders.nil? ret['d'] = @recursive_folders end @unknown_json_fields.each do |k, v| ret[k] = v end ret end
@return [String] The complete object as a JSON string
# File lib/comet/models/stored_object.rb, line 233 def to_json(options = {}) to_hash.to_json(options) end