Class: Curie
- Inherits:
-
Object
- Object
- Curie
- Defined in:
- lib/curies/curie.rb
Constant Summary collapse
- DEFAULT_MAPPINGS =
{"cal" => "http://www.w3.org/2002/12/cal/ical#", "cc" => "http://creativecommons.org/ns#", "contact" => "http://www.w3.org/2001/vcard-rdf/3.0#", "dc" => "http://purl.org/dc/elements/1.1/", "foaf" => "http://xmlns.com/foaf/0.1/", "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs" => "http://www.w3.org/2000/01/rdf-schema#", "xsd" => "http://www.w3.org/2001/XMLSchema#", "http" => "http" }
- @@mappings =
{}
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
Class Method Summary collapse
- .add_prefixes!(mappings) ⇒ Object
- .parse(curie_string, opts = {}) ⇒ Object
- .qualified_uri_for(prefix) ⇒ Object
- .remove_prefixes!(prefixes) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(prefix, reference) ⇒ Curie
constructor
A new instance of Curie.
- #to_s ⇒ Object
Constructor Details
#initialize(prefix, reference) ⇒ Curie
Returns a new instance of Curie.
33 34 35 |
# File 'lib/curies/curie.rb', line 33 def initialize(prefix, reference) @prefix, @reference = prefix, reference end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
30 31 32 |
# File 'lib/curies/curie.rb', line 30 def prefix @prefix end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
31 32 33 |
# File 'lib/curies/curie.rb', line 31 def reference @reference end |
Class Method Details
.add_prefixes!(mappings) ⇒ Object
72 73 74 |
# File 'lib/curies/curie.rb', line 72 def self.add_prefixes!(mappings) @@mappings.merge! mappings.stringify_keys end |
.parse(curie_string, opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/curies/curie.rb', line 42 def self.parse(curie_string, opts = {}) if opts[:treat_unsafe_as_normal_strings] and not curie_string.could_be_a_safe_curie? a = [curie_string, :string] return a end if not(curie_string.index(':')) #just some random string that doesn't even have a colon! #strip off brackets if they exist curie_string = curie_string[1,curie_string.length-2] if curie_string.could_be_a_safe_curie? return curie_string elsif curie_string.could_be_a_safe_curie? pivot = curie_string.index(':') prefix = curie_string[1,pivot-1] reference = curie_string[pivot+1, curie_string.length].chop else pivot = curie_string.index(':') prefix = curie_string[0,pivot] reference = curie_string[pivot+1, curie_string.length] end if opts[:in_parts] return [qualified_uri_for(prefix), reference] else return qualified_uri_for(prefix) + reference end end |
.qualified_uri_for(prefix) ⇒ Object
67 68 69 70 |
# File 'lib/curies/curie.rb', line 67 def self.qualified_uri_for(prefix) return @@mappings[prefix] if @@mappings[prefix] raise "Sorry, no namespace or prefix registered for curies with the prefix #{prefix}" end |
.remove_prefixes!(prefixes) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/curies/curie.rb', line 76 def self.remove_prefixes!(prefixes) prefixes = [prefixes] unless prefixes.respond_to? :each for prefix in prefixes @@mappings.delete prefix.to_s end end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 |
# File 'lib/curies/curie.rb', line 37 def ==(other) return false unless other.is_a?(Curie) return true if self.to_s == other.to_s end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/curies/curie.rb', line 83 def to_s "[#{@prefix}:#{@reference}]" end |