Class: Palm::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/palm/palm_record.rb

Overview

Base class for all Palm::PDB Records. This stores the basic metadata for each record. Subclasses should extend this provide a useful interface for accessing specific record types.

Direct Known Subclasses

RawRecord, WabaRecord

Constant Summary collapse

RECORD_ATTRIBUTE_CODES =
{
	:expunged 	=>    0x80,
	:dirty 	 		=>    0x40,
	:deleted  	=>    0x20,
	:private   	=>    0x10
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecord

Returns a new instance of Record.



16
17
18
19
20
# File 'lib/palm/palm_record.rb', line 16

def initialize
	@category = 	0
	@record_id = 	0
	@dirty = 			true
end

Instance Attribute Details

#archiveObject

Returns the value of attribute archive.



13
14
15
# File 'lib/palm/palm_record.rb', line 13

def archive
  @archive
end

#categoryObject

Returns the value of attribute category.



14
15
16
# File 'lib/palm/palm_record.rb', line 14

def category
  @category
end

#deletedObject

Returns the value of attribute deleted.



13
14
15
# File 'lib/palm/palm_record.rb', line 13

def deleted
  @deleted
end

#dirtyObject

Returns the value of attribute dirty.



13
14
15
# File 'lib/palm/palm_record.rb', line 13

def dirty
  @dirty
end

#expungedObject

Returns the value of attribute expunged.



13
14
15
# File 'lib/palm/palm_record.rb', line 13

def expunged
  @expunged
end

#privateObject

Returns the value of attribute private.



13
14
15
# File 'lib/palm/palm_record.rb', line 13

def private
  @private
end

#record_idObject

Returns the value of attribute record_id.



14
15
16
# File 'lib/palm/palm_record.rb', line 14

def record_id
  @record_id
end

Instance Method Details

#packed_attributesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/palm/palm_record.rb', line 22

def packed_attributes
	encoded = 0
	if @expunged or @deleted
		encoded |= 0x08 if @archive
	else
		encoded = @category & 0x0f
	end
	
	RECORD_ATTRIBUTE_CODES.each do |name,code|
		encoded |= code if send(name)
	end
	
	encoded
end

#packed_attributes=(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/palm/palm_record.rb', line 37

def packed_attributes=(value)
	RECORD_ATTRIBUTE_CODES.each do |key,code|
		self.send("#{key}=", (value & code) > 0)
	end
	if (value & 0xa0) == 0
		@category = (value & 0x0f)
	else
		@archive = (value & 0x08) > 0
	end
end