Class: Id

Inherits:
Object
  • Object
show all
Defined in:
lib/r43/id.rb

Overview

Implements an id object. This object encapsulates the 43 Things id string format of “tag:43things.com:joshp:entry:33”. Currently, intended to be constructed only by other domain objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeId

Returns a new instance of Id.



13
14
15
16
# File 'lib/r43/id.rb', line 13

def initialize()
  # just to initialize the object, we'll always feed the attributes
  # in some other way
end

Instance Attribute Details

#int_valueObject

Returns the value of attribute int_value.



11
12
13
# File 'lib/r43/id.rb', line 11

def int_value
  @int_value
end

#string_valueObject

Returns the value of attribute string_value.



11
12
13
# File 'lib/r43/id.rb', line 11

def string_value
  @string_value
end

Class Method Details

.from_xml(xml) ⇒ Object

Builds an Id object from the format “<id>tag:43things.com:joshp:entry:33</id>”



30
31
32
33
34
35
36
37
# File 'lib/r43/id.rb', line 30

def Id.from_xml(xml)
  id = Id.new()
  xml.text =~ /^(.*:(\d+))$/
  id.string_value= $1
  id.int_value= $2.to_i

  id
end

Instance Method Details

#to_iObject



18
19
20
# File 'lib/r43/id.rb', line 18

def to_i()
  @int_value
end

#to_sObject



22
23
24
# File 'lib/r43/id.rb', line 22

def to_s()
  @string_value
end