Class: Factoid::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/factoid/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, uri, default, value) ⇒ Source

Returns a new instance of Source.


8
9
10
11
12
13
# File 'lib/factoid/source.rb', line 8

def initialize(uuid, uri, default, value)
	@uuid = uuid
	@uri = Addressable::URI.parse(uri)
	@default = default
	@value = value
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri


16
17
18
# File 'lib/factoid/source.rb', line 16

def uri
  @uri
end

#uuidObject (readonly)

Returns the value of attribute uuid


15
16
17
# File 'lib/factoid/source.rb', line 15

def uuid
  @uuid
end

#valueObject (readonly)

Returns the value of attribute value


17
18
19
# File 'lib/factoid/source.rb', line 17

def value
  @value
end

Class Method Details

.from_xml(elem) ⇒ Object


69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/factoid/xml.rb', line 69

def Source.from_xml(elem)
	uuid = elem.attr('xml:id')

	uri = elem.attr('xlink:href')

	default = (elem.attr('default') == 'true')

	#value = Value.from_xml(elem)
	value = Value::EMPTY

	return Source.new(uuid, uri, default, value)
end

Instance Method Details

#==(other) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/factoid/source.rb', line 28

def ==(other)
	if other.equal?(self)
		return true
	end

	if other.is_a?(Source)
		if other.ref?
			return other.uri == self.uri
		else
			return other.value == self.value
		end
	end

	if ref?
		return Addressable::URI.parse(other) == @uri
	else
		return other == @value.to_s
	end
end

#default?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/factoid/source.rb', line 19

def default?
	return @default
end

#ref?Boolean

Returns:

  • (Boolean)

23
24
25
26
# File 'lib/factoid/source.rb', line 23

def ref?
	# FIXME: separate SourceRef class
	return !@uri.nil?
end