Class: Ldpath::FieldMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/ldpath/field_mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, selector:, field_type: nil, options: {}) ⇒ FieldMapping

Returns a new instance of FieldMapping.



7
8
9
10
11
12
# File 'lib/ldpath/field_mapping.rb', line 7

def initialize(name:, selector:, field_type: nil, options: {})
  @name = name.to_s
  @selector = selector
  @field_type = field_type
  @options = options
end

Instance Attribute Details

#field_typeObject (readonly)

Returns the value of attribute field_type.



5
6
7
# File 'lib/ldpath/field_mapping.rb', line 5

def field_type
  @field_type
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ldpath/field_mapping.rb', line 5

def name
  @name
end

#selectorObject (readonly)

Returns the value of attribute selector.



5
6
7
# File 'lib/ldpath/field_mapping.rb', line 5

def selector
  @selector
end

Instance Method Details

#evaluate(program, uri, context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ldpath/field_mapping.rb', line 14

def evaluate(program, uri, context)
  case selector
  when Ldpath::Selector
    return to_enum(:evaluate, program, uri, context) unless block_given?

    selector.evaluate(program, uri, context).each do |value|
      yield transform_value(value)
    end
  when RDF::Literal
    Array(selector.canonicalize.object)
  else
    Array(selector)
  end
end