class Gearbox::Attribute
Attributes
datatype[RW]
Options to figure out: more index options, routing, triple pattern
index[RW]
Options to figure out: more index options, routing, triple pattern
language[RW]
Options to figure out: more index options, routing, triple pattern
name[RW]
Options to figure out: more index options, routing, triple pattern
predicate[RW]
Options to figure out: more index options, routing, triple pattern
repository[RW]
Options to figure out: more index options, routing, triple pattern
reverse[RW]
Options to figure out: more index options, routing, triple pattern
subject_decorator[R]
value[RW]
Options to figure out: more index options, routing, triple pattern
Public Class Methods
new(opts={})
click to toggle source
# File lib/gearbox/attribute.rb, line 9 def initialize(opts={}) set(opts.delete(:value) || :_value_not_set) assert_defaults extract_from_statement(opts) if opts.has_key?(:statement) assert_options(opts) end
Public Instance Methods
literal(opts={:value => :_value_not_set})
click to toggle source
# File lib/gearbox/attribute.rb, line 39 def literal(opts={:value => :_value_not_set}) value = opts.delete(:value) value = to_value if value == :_value_not_set opts = {:language => self.language, :datatype => self.datatype}.merge(opts) value = case opts[:datatype] when :boolean RDF::Literal::Boolean.new(value) when :date RDF::Literal::Date.new(value) when :date_time RDF::Literal::DateTime.new(value) when :decimal RDF::Literal::Decimal.new(value) when :double RDF::Literal::Double.new(value) when :time RDF::Literal::Time.new(value) when :token RDF::Literal::Token.new(value) when :xml RDF::Literal::XML.new(value) else value end RDF::Literal.new(value, opts) end
set(value=:_value_not_set, opts={})
click to toggle source
# File lib/gearbox/attribute.rb, line 67 def set(value=:_value_not_set, opts={}) opts = {:value => value}.merge(opts) @value = literal(opts).object end
subject()
click to toggle source
TODO: I’m a little quesy about the relationship between the model class, the model, and the attribute. I’m going to have to rebuild the model DSL and see how this stuff gets built.
# File lib/gearbox/attribute.rb, line 22 def subject return nil unless subject_decorator if subject_decorator.respond_to?(:call) subject_decorator.call() elsif respond_to?(subject_decorator) self.send(subject_decorator) else nil end end
subject_decorator=(value=nil, &block)
click to toggle source
# File lib/gearbox/attribute.rb, line 16 def subject_decorator=(value=nil, &block) @subject_decorator = block_given? ? block : value end
to_rdf(model, opts={})
click to toggle source
# File lib/gearbox/attribute.rb, line 72 def to_rdf(model, opts={}) opts[:value] = :_value_not_set unless opts.has_key?(:value) opts = { :reverse => self.reverse, :predicate => self.predicate, :value => self.literal(opts) }.merge(opts) subject = self.subject subject ||= model.subject subject = RDF::URI.new(subject) predicate = opts[:predicate] object = opts[:value] return opts[:reverse] ? RDF::Statement(object, predicate, subject) : RDF::Statement(subject, predicate, object) end
to_value()
click to toggle source
# File lib/gearbox/attribute.rb, line 33 def to_value # Skipping the serialization steps for a moment. @value end
Also aliased as: get
Private Instance Methods
assert_defaults()
click to toggle source
# File lib/gearbox/attribute.rb, line 92 def assert_defaults self.index = false self.reverse = false end
assert_options(opts)
click to toggle source
# File lib/gearbox/attribute.rb, line 97 def assert_options(opts) opts.each do |accessor, value| send("#{accessor}=", value) if respond_to?("#{accessor}=") end end
can_infer_reverse_from_model?(model, object)
click to toggle source
# File lib/gearbox/attribute.rb, line 121 def can_infer_reverse_from_model?(model, object) return false unless model model.subject.to_s == object.to_s end
extract_from_literal(literal)
click to toggle source
# File lib/gearbox/attribute.rb, line 114 def extract_from_literal(literal) return literal unless literal.is_a?(RDF::Literal) self.language = literal.language self.datatype = literal.datatype literal.object end
extract_from_statement(opts)
click to toggle source
# File lib/gearbox/attribute.rb, line 103 def extract_from_statement(opts) statement = opts[:statement] object = statement.object self.reverse = can_infer_reverse_from_model?(opts[:model], object) object = statement.subject if self.reverse self.predicate = statement.predicate self.set extract_from_literal(object) end