Class: Rena::Literal::Encoding
- Inherits:
-
Object
- Object
- Rena::Literal::Encoding
- Defined in:
- lib/rena/literal.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Null
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .coerce(string_or_nil) ⇒ Object
- .float ⇒ Object
- .integer ⇒ Object
- .string ⇒ Object
- .the_null_encoding ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #format_as_n3(content) ⇒ Object
- #format_as_trix(value) ⇒ Object
- #hash ⇒ Object
-
#initialize(value) ⇒ Encoding
constructor
A new instance of Encoding.
- #should_quote? ⇒ Boolean
- #to_s ⇒ Object
- #xmlliteral? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Encoding
Returns a new instance of Encoding.
51 52 53 |
# File 'lib/rena/literal.rb', line 51 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
50 51 52 |
# File 'lib/rena/literal.rb', line 50 def value @value end |
Class Method Details
.coerce(string_or_nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rena/literal.rb', line 16 def self.coerce(string_or_nil) if string_or_nil.nil? || string_or_nil == '' the_null_encoding else new string_or_nil end end |
.float ⇒ Object
8 9 10 |
# File 'lib/rena/literal.rb', line 8 def self.float @float ||= coerce "http://www.w3.org/2001/XMLSchema#float" end |
.integer ⇒ Object
4 5 6 |
# File 'lib/rena/literal.rb', line 4 def self.integer @integer ||= coerce "http://www.w3.org/2001/XMLSchema#int" end |
.string ⇒ Object
12 13 14 |
# File 'lib/rena/literal.rb', line 12 def self.string @string ||= coerce "http://www.w3.org/2001/XMLSchema#string" end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rena/literal.rb', line 59 def ==(other) case other when String other == @value when self.class other.value == @value else false end end |
#format_as_n3(content) ⇒ Object
78 79 80 81 |
# File 'lib/rena/literal.rb', line 78 def format_as_n3(content) quoted_content = should_quote? ? "\"#{content}\"" : content "#{quoted_content}^^<#{value}>" end |
#format_as_trix(value) ⇒ Object
83 84 85 |
# File 'lib/rena/literal.rb', line 83 def format_as_trix(value) "<typedLiteral datatype=\"#{@value}\">#{value}</typedLiteral>" end |
#hash ⇒ Object
70 71 72 |
# File 'lib/rena/literal.rb', line 70 def hash @value.hash end |
#should_quote? ⇒ Boolean
55 56 57 |
# File 'lib/rena/literal.rb', line 55 def should_quote? @value != self.class.integer.to_s end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/rena/literal.rb', line 74 def to_s @value end |
#xmlliteral? ⇒ Boolean
87 88 89 |
# File 'lib/rena/literal.rb', line 87 def xmlliteral? @value == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" end |