Class: TaliaCore::PropertyString

Inherits:
String
  • Object
show all
Defined in:
lib/talia_core/property_string.rb

Overview

Handling of RDF string values. These values can contain both locale (language) and type information. (E.g. “Some value^^string@en”)

This class will parse the value string an make all elements available as separate accessors.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#to_permalink, #to_uri

Constructor Details

#initialize(property_string = '', language = nil, type = nil) ⇒ PropertyString

Create a new object from the given values. No parsing is done here.



18
19
20
21
22
# File 'lib/talia_core/property_string.rb', line 18

def initialize(property_string = '', language = nil, type = nil)
  @lang = language
  @type = type
  self.replace(property_string)
end

Instance Attribute Details

#langObject

Returns the value of attribute lang.



10
11
12
# File 'lib/talia_core/property_string.rb', line 10

def lang
  @lang
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/talia_core/property_string.rb', line 10

def type
  @type
end

Class Method Details

.parse(property_string) ⇒ Object

Create a new object by parsing the given property string



13
14
15
# File 'lib/talia_core/property_string.rb', line 13

def self.parse(property_string)
  self.new.parse(property_string)
end

Instance Method Details

#inspectObject

Inspect shows the real content



44
45
46
# File 'lib/talia_core/property_string.rb', line 44

def inspect
  "\"#{self}\" <lang: #{lang.inspect} - type: #{type.inspect}>"
end

#parse(property_string) ⇒ Object

Parses the given string into a PropertyString



25
26
27
28
29
30
31
32
# File 'lib/talia_core/property_string.rb', line 25

def parse(property_string)
  # First split for the type
  type_split = property_string.split('^^')
  # Check if any of the elements contains a language string
  type_split = type_split.collect { |el| extract_lang(el) }
  @type = (type_split.size > 1) ? type_split.last : nil
  self.replace(type_split.first || '')
end

#to_rdfObject

Gives the “internal representation” - this should be equivalent to the string from which the object was created



36
37
38
39
40
41
# File 'lib/talia_core/property_string.rb', line 36

def to_rdf
  value = self.clone
  value << '^^' << type if(type)
  value << '@' << lang if(lang)
  value
end