Class: Label::SKOSXL::Properties::LiteralForm

Inherits:
Object
  • Object
show all
Defined in:
app/models/label/skosxl/properties/literal_form.rb

Class Method Summary collapse

Class Method Details

.build_from_rdf(rdf_subject, rdf_predicate, rdf_object) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/label/skosxl/properties/literal_form.rb', line 6

def self.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
  unless rdf_object =~ RDFAPI::LITERAL_REGEXP
    raise InvalidStringLiteralError,
      "#{self.name}#build_from_rdf: Object (#{rdf_object}) must be a string literal"
  end

  lang = $3
  value = begin
    JSON.parse(%Q{["#{$1}"]})[0].gsub('\\n', "\n") # Trick to decode \uHHHHH chars
  rescue JSON::ParserError
    $1
  end

  rdf_subject.update(value: value, language: lang)
end