Class: RDF::Literal::Integer
- Inherits:
-
Decimal
- Object
- RDF::Literal
- Numeric
- Decimal
- RDF::Literal::Integer
- Defined in:
- lib/rdf/model/literal/integer.rb
Overview
An integer literal.
Constant Summary
- DATATYPE =
XSD.integer
- GRAMMAR =
/^[\+\-]?\d+$/.freeze
Constants inherited from RDF::Literal
Instance Attribute Summary
Attributes inherited from RDF::Literal
Instance Method Summary (collapse)
-
- (RDF::Literal) abs
Returns the absolute value of
self. -
- (RDF::Literal) canonicalize!
Converts this literal into its canonical lexical representation.
-
- (Boolean) even?
Returns
trueif the value is even. -
- (Integer) initialize(value, options = {})
constructor
A new instance of Integer.
-
- (Boolean) nonzero?
Returns
selfif the value is not zero,nilotherwise. -
- (Boolean) odd?
Returns
trueif the value is odd. -
- (RDF::Literal) pred
Returns the successor value of
self. -
- (RDF::Literal) succ
(also: #next)
Returns the predecessor value of
self. -
- (OpenSSL::BN) to_bn
Returns the value as an
OpenSSL::BNinstance. -
- (String) to_s
Returns the value as a string.
-
- (Boolean) zero?
Returns
trueif the value is zero.
Methods inherited from Numeric
#*, #+, #+@, #-, #-@, #/, #<=>, #==, #to_d, #to_f, #to_i, #to_r
Methods inherited from RDF::Literal
#==, #anonymous?, #canonicalize, #comperable_datatype?, #eql?, #has_datatype?, #has_language?, #hash, #inspect, #invalid?, #literal?, #object, #plain?, #valid?, #validate!, #value
Methods included from Term
#<=>, #==, #constant?, #eql?, #variable?
Methods included from Value
#graph?, #inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #statement?, #to_ntriples, #to_quad, #to_rdf, #type_error, #uri?, #variable?
Constructor Details
- (Integer) initialize(value, options = {})
A new instance of Integer
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rdf/model/literal/integer.rb', line 21 def initialize(value, = {}) @datatype = RDF::URI([:datatype] || self.class.const_get(:DATATYPE)) @string = [:lexical] if .has_key?(:lexical) @string ||= value if value.is_a?(String) @object = case when value.is_a?(::String) then Integer(value) rescue nil when value.is_a?(::Integer) then value when value.respond_to?(:to_i) then value.to_i else Integer(value.to_s) rescue nil end end |
Instance Method Details
- (RDF::Literal) abs
Returns the absolute value of self.
85 86 87 |
# File 'lib/rdf/model/literal/integer.rb', line 85 def abs (n = to_i) && n > 0 ? self : RDF::Literal(n.abs) end |
- (RDF::Literal) canonicalize!
Converts this literal into its canonical lexical representation.
38 39 40 41 |
# File 'lib/rdf/model/literal/integer.rb', line 38 def canonicalize! @string = @object.to_s if @object self end |
- (Boolean) even?
Returns true if the value is even.
67 68 69 |
# File 'lib/rdf/model/literal/integer.rb', line 67 def even? to_i.even? end |
- (Boolean) nonzero?
Returns self if the value is not zero, nil otherwise.
103 104 105 |
# File 'lib/rdf/model/literal/integer.rb', line 103 def nonzero? to_i.nonzero? ? self : nil end |
- (Boolean) odd?
Returns true if the value is odd.
76 77 78 |
# File 'lib/rdf/model/literal/integer.rb', line 76 def odd? to_i.odd? end |
- (RDF::Literal) pred
Returns the successor value of self.
48 49 50 |
# File 'lib/rdf/model/literal/integer.rb', line 48 def pred RDF::Literal(to_i.pred) end |
- (RDF::Literal) succ Also known as: next
Returns the predecessor value of self.
57 58 59 |
# File 'lib/rdf/model/literal/integer.rb', line 57 def succ RDF::Literal(to_i.succ) end |
- (OpenSSL::BN) to_bn
Returns the value as an OpenSSL::BN instance.
121 122 123 124 |
# File 'lib/rdf/model/literal/integer.rb', line 121 def to_bn require 'openssl' unless defined?(OpenSSL::BN) OpenSSL::BN.new(to_s) end |
- (String) to_s
Returns the value as a string.
111 112 113 |
# File 'lib/rdf/model/literal/integer.rb', line 111 def to_s @string || @object.to_s end |
- (Boolean) zero?
Returns true if the value is zero.
94 95 96 |
# File 'lib/rdf/model/literal/integer.rb', line 94 def zero? to_i.zero? end |