Module: Tripod::Fields::ClassMethods

Defined in:
lib/tripod/fields.rb

Instance Method Summary collapse

Instance Method Details

#field(name, predicate, options = {}) ⇒ Field

Defines all the fields that are accessible on the Resource For each field that is defined, a getter and setter will be added as an instance method to the Resource.

 @option options [ String, RDF::URI ] datatype The uri of the datatype for the field (will be used to create an RDF::Literal of the right type on the way in only).

Examples:

Define a field.

field :name, :predicate => 'http://name'

Parameters:

  • name (Symbol)

    The name of the field.

  • predicate (String, RDF::URI)

    The predicate for the field.

  • options (Hash) (defaults to: {})

    The options to pass to the field.

Options Hash (options):

  • multivalued (Boolean)

    Is this a multi-valued field? Default is false.

Returns:

  • (Field)

    The generated field



30
31
32
33
# File 'lib/tripod/fields.rb', line 30

def field(name, predicate, options = {})
  # TODO: validate the field params/options here..
  add_field(name, predicate, options)
end

#new_value_for_field(value, field) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/tripod/fields.rb', line 36

def new_value_for_field(value, field)
  if field.is_uri?
    RDF::URI.new(value.to_s)
  elsif field.datatype
    RDF::Literal.new(value, :datatype => field.datatype)
  else
    value
  end
end