Class: RDFMapper::Model::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/model/property.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance, options = {}, *args) ⇒ Property

Returns a new instance of Property.



5
6
7
8
9
10
# File 'lib/lib/model/property.rb', line 5

def initialize(instance, options = {}, *args)
  @instance = instance
  @options = options
  @value = nil
  @new = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object

-


72
73
74
# File 'lib/lib/model/property.rb', line 72

def method_missing(symbol, *args, &block)
  @value.send(symbol, *args, &block)
end

Instance Method Details

#inspectString

Developer-friendly representation of the instance

Returns:

  • (String)


65
66
67
# File 'lib/lib/model/property.rb', line 65

def inspect #nodoc
  @value.inspect
end

#new?Boolean

Checks if property has default (nil) value.

Parameters:

  • (Boolean)

Returns:

  • (Boolean)


17
18
19
# File 'lib/lib/model/property.rb', line 17

def new?
  @new
end

#object(*args) ⇒ Object

-


47
48
49
# File 'lib/lib/model/property.rb', line 47

def object(*args)
  @value
end

#replace(value) ⇒ Object

Assigns a new value to the property.

Parameters:

  • value (Object)

Returns:

  • (Object)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lib/model/property.rb', line 27

def replace(value)
  @new = false
  if value.kind_of? Array
    value = value.first
  end
  if value.kind_of? RDF::Literal
    value = value.object
  end
  @value = case @options[:type]
    when :text      then value.to_s
    when :integer   then value.to_i
    when :float     then value.to_f
    when :uri       then RDF::URI.new(value.to_s)
    else value.to_s
  end
end

#to_statements(options = {}) ⇒ Object

-


54
55
56
57
58
# File 'lib/lib/model/property.rb', line 54

def to_statements(options = {})
  { :subject => @instance.id,
    :predicate => @options[:type],
    :object => RDF::Literal.new(@value) }
end