Class: Factoid::Value

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

Defined Under Namespace

Classes: EntitoidInterpreter, IndentityInterpreter, XSDDateInterpreter

Constant Summary collapse

EMPTY =
Value.new(nil, nil).freeze
Interpreters =
[
	XSDDateInterpreter,
	EntitoidInterpreter,
	IndentityInterpreter,
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, raw_value) ⇒ Value

Returns a new instance of Value.


6
7
8
9
# File 'lib/factoid/value.rb', line 6

def initialize(type, raw_value)
	@type = type
	@raw_value = raw_value
end

Class Method Details

.from_xml(container_elem) ⇒ Object


82
83
84
85
86
87
88
89
90
# File 'lib/factoid/xml.rb', line 82

def Value.from_xml(container_elem)
	elem = container_elem.at('./f:value', NS)

	type = elem.attr('type')	# TODO: special case for entitoids
	# TODO: use type = :entitoid_ref instead of nil


	return Value.new(type, elem)
end

Instance Method Details

#value(interpret, follow) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/factoid/value.rb', line 13

def value(interpret, follow)
	raw = nil

	if @raw_value.elements.empty?
		raw = @raw_value.text
	else
		raw = @raw_value
	end

	if !interpret
		return raw
	end

	interpreter = Interpreters.find { |i| begin i.accept?(@type, raw); rescue; end; }
	v = interpreter.interpret(@type, raw)

	if !follow
		return v
	end

	# FIXME: use Dereferenciators (like Interpreters)
	if v.is_a? EntitoidRef
		r = v.deref
	else
		r = v
	end

	return r
end