Class: Factoid::Factoid
- Inherits:
-
Object
- Object
- Factoid::Factoid
- Defined in:
- lib/factoid/factoid.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value_obj ⇒ Object
readonly
Returns the value of attribute value_obj.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
-
#initialize(type, context, value_obj, sources, context_sources) ⇒ Factoid
constructor
A new instance of Factoid.
- #match?(type, context) ⇒ Boolean
- #sources ⇒ Object
- #value(interpret = true, follow = false) ⇒ Object
Constructor Details
#initialize(type, context, value_obj, sources, context_sources) ⇒ Factoid
Returns a new instance of Factoid.
6 7 8 9 10 11 12 13 |
# File 'lib/factoid/factoid.rb', line 6 def initialize(type, context, value_obj, sources, context_sources) @type = type @context = context @value_obj = value_obj @sources = sources @context_sources = context_sources end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
17 18 19 |
# File 'lib/factoid/factoid.rb', line 17 def context @context end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/factoid/factoid.rb', line 15 def type @type end |
#value_obj ⇒ Object (readonly)
Returns the value of attribute value_obj.
16 17 18 |
# File 'lib/factoid/factoid.rb', line 16 def value_obj @value_obj end |
Class Method Details
.from_xml(elem, context_sources) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/factoid/xml.rb', line 50 def Factoid.from_xml(elem, context_sources) type = elem.name unless elem.name == 'factoid' type ||= elem.attr('type') context = {} elem.xpath('./*[name(.) != "value"]').each do |e| context[e.name] = e.text end value = Value.from_xml(elem) raw_sources = elem.xpath('f:source', NS) sources = raw_sources.map do |e| Source.from_xml(e) end return Factoid.new(type, context, value, sources, context_sources) end |
Instance Method Details
#eql?(other) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/factoid/factoid.rb', line 41 def eql?(other) if other.equal?(self) return true end if other.class != self.class return false end same = other.type == self.type && other.value.eql?(self.value) && other.sources == self.sources return same end |
#match?(type, context) ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/factoid/factoid.rb', line 29 def match?(type, context) if @type != type # FIXME: check type hierarchy return false end return context.to_a.all? { |k, v| @context[k.to_s] == v } end |
#sources ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/factoid/factoid.rb', line 19 def sources if !@sources.empty? return @sources end uris = @context_sources.select { |s| s.default? } return uris end |
#value(interpret = true, follow = false) ⇒ Object
37 38 39 |
# File 'lib/factoid/factoid.rb', line 37 def value(interpret = true, follow = false) return @value_obj.value(interpret, follow) end |