Class: Gearbox::Attribute
- Inherits:
-
Object
- Object
- Gearbox::Attribute
- Defined in:
- lib/gearbox/attribute.rb
Instance Attribute Summary collapse
-
#datatype ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#index ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#language ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#name ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#predicate ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#repository ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#reverse ⇒ Object
Options to figure out: more index options, routing, triple pattern.
-
#subject_decorator ⇒ Object
Returns the value of attribute subject_decorator.
-
#value ⇒ Object
Options to figure out: more index options, routing, triple pattern.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #literal(opts = {:value => :_value_not_set}) ⇒ Object
- #set(value = :_value_not_set, opts = {}) ⇒ Object
-
#subject ⇒ Object
TODO: I’m a little quesy about the relationship between the model class, the model, and the attribute.
- #to_rdf(model, opts = {}) ⇒ Object
- #to_value ⇒ Object (also: #get)
Constructor Details
#initialize(opts = {}) ⇒ Attribute
Returns a new instance of Attribute.
9 10 11 12 13 14 |
# 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) (opts) end |
Instance Attribute Details
#datatype ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def datatype @datatype end |
#index ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def index @index end |
#language ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def language @language end |
#name ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def name @name end |
#predicate ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def predicate @predicate end |
#repository ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def repository @repository end |
#reverse ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def reverse @reverse end |
#subject_decorator ⇒ Object
Returns the value of attribute subject_decorator.
7 8 9 |
# File 'lib/gearbox/attribute.rb', line 7 def subject_decorator @subject_decorator end |
#value ⇒ Object
Options to figure out: more index options, routing, triple pattern
6 7 8 |
# File 'lib/gearbox/attribute.rb', line 6 def value @value end |
Instance Method Details
#literal(opts = {:value => :_value_not_set}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 = {}) ⇒ Object
67 68 69 70 |
# 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 ⇒ Object
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.
22 23 24 25 26 27 28 29 30 31 |
# 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 |
#to_rdf(model, opts = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 ⇒ Object Also known as: get
33 34 35 36 |
# File 'lib/gearbox/attribute.rb', line 33 def to_value # Skipping the serialization steps for a moment. @value end |