Class: RDF::Literal::Integer
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb
Overview
An integer literal.
Direct Known Subclasses
Constant Summary collapse
Constants inherited from RDF::Literal
FALSE, TRUE, XSD_STRING, ZERO
Constants included from N3::Terminals
N3::Terminals::ANON, N3::Terminals::BASE, N3::Terminals::BLANK_NODE_LABEL, N3::Terminals::DECIMAL, N3::Terminals::DOUBLE, N3::Terminals::ECHAR, N3::Terminals::ESCAPE_CHAR4, N3::Terminals::ESCAPE_CHAR8, N3::Terminals::EXPONENT, N3::Terminals::INTEGER, N3::Terminals::IPLSTART, N3::Terminals::IRIREF, N3::Terminals::IRI_RANGE, N3::Terminals::LANGTAG, N3::Terminals::PERCENT, N3::Terminals::PLX, N3::Terminals::PNAME_LN, N3::Terminals::PNAME_NS, N3::Terminals::PN_CHARS, N3::Terminals::PN_CHARS_BASE, N3::Terminals::PN_CHARS_BODY, N3::Terminals::PN_CHARS_U, N3::Terminals::PN_LOCAL, N3::Terminals::PN_LOCAL_BODY, N3::Terminals::PN_LOCAL_ESC, N3::Terminals::PN_PREFIX, N3::Terminals::PREFIX, N3::Terminals::QUICK_VAR_NAME, N3::Terminals::STRING_LITERAL_LONG_QUOTE, N3::Terminals::STRING_LITERAL_LONG_SINGLE_QUOTE, N3::Terminals::STRING_LITERAL_QUOTE, N3::Terminals::STRING_LITERAL_SINGLE_QUOTE, N3::Terminals::UCHAR, N3::Terminals::U_CHARS1, N3::Terminals::U_CHARS2, N3::Terminals::WS
Constants included from SPARQL::Algebra::Expression
SPARQL::Algebra::Expression::PATTERN_PARENTS
Constants included from Util::Logger
Instance Attribute Summary
Attributes inherited from RDF::Literal
#datatype, #direction, #language
Instance Method Summary collapse
-
#abs ⇒ RDF::Literal
Returns the absolute value of
self
. -
#canonicalize! ⇒ RDF::Literal
Converts this literal into its canonical lexical representation.
-
#even? ⇒ Boolean
Returns
true
if the value is even. -
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Integer
constructor
A new instance of Integer.
-
#nonzero? ⇒ Boolean
Returns
self
if the value is not zero,nil
otherwise. -
#odd? ⇒ Boolean
Returns
true
if the value is odd. -
#pred ⇒ RDF::Literal
Returns the predecessor value of
self
. -
#round ⇒ RDF::Literal
Returns
self
. -
#succ ⇒ RDF::Literal
(also: #next)
Returns the successor value of
self
. -
#to_bn ⇒ OpenSSL::BN
Returns the value as an
OpenSSL::BN
instance. -
#to_s ⇒ String
Returns the value as a string.
-
#zero? ⇒ Boolean
Returns
true
if the value is zero.
Methods inherited from Decimal
Methods inherited from Numeric
#%, #*, #**, #+, #+@, #-, #-@, #/, #<=>, #==, #acos, #asin, #atan, #atan2, #ceil, #cos, #exp, #exp10, #floor, #log, #log10, #sin, #sqrt, #tan, #to_d, #to_f, #to_i, #to_r
Methods inherited from RDF::Literal
#<=>, #==, #as_datetime, #as_number, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, #direction?, #english?, #eql?, #escape, #hash, #humanize, #inspect, #language?, #literal?, #method_missing, #object, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #valid_extended?, #validate!, #value, #value_hash
Methods included from Term
#<=>, #==, #aggregate?, #as_datetime, #as_number, #compatible?, #eql?, #escape, #evaluate, #ndvars, #optimize, #sameTerm?, #term?, #terms, #to_base, #to_sparql, #to_term, #vars
Methods included from SPARQL::Algebra::Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Methods included from Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Methods included from Value
#anonymous?, #canonicalize, #constant?, #formula?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_ndvar, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?
Constructor Details
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Integer
Returns a new instance of Integer.
21 22 23 24 25 26 27 28 29 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 21 def initialize(value, datatype: nil, lexical: nil, **) @datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE)) @string = lexical || (value if value.is_a?(String)) @object = case when value.is_a?(::Integer) then value when value.respond_to?(:to_i) then value.to_i else 0 end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Literal
Instance Method Details
#abs ⇒ RDF::Literal
Returns the absolute value of self
.
From the XQuery function fn:abs.
86 87 88 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 86 def abs (n = to_i) && n > 0 ? self : self.class.new(n.abs) end |
#canonicalize! ⇒ RDF::Literal
Converts this literal into its canonical lexical representation.
36 37 38 39 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 36 def canonicalize! @string = @object.to_s if @object self end |
#even? ⇒ Boolean
Returns true
if the value is even.
65 66 67 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 65 def even? to_i.even? end |
#nonzero? ⇒ Boolean
Returns self
if the value is not zero, nil
otherwise.
115 116 117 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 115 def nonzero? to_i.nonzero? ? self : nil end |
#odd? ⇒ Boolean
Returns true
if the value is odd.
74 75 76 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 74 def odd? to_i.odd? end |
#pred ⇒ RDF::Literal
Returns the predecessor value of self
.
46 47 48 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 46 def pred RDF::Literal(to_i.pred) end |
#round ⇒ RDF::Literal
Returns self
.
From the XQuery function fn:round.
97 98 99 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 97 def round self end |
#succ ⇒ RDF::Literal Also known as: next
Returns the successor value of self
.
55 56 57 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 55 def succ RDF::Literal(to_i.succ) end |
#to_bn ⇒ OpenSSL::BN
Returns the value as an OpenSSL::BN
instance.
133 134 135 136 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 133 def to_bn require 'openssl' unless defined?(OpenSSL::BN) OpenSSL::BN.new(to_s) end |
#to_s ⇒ String
Returns the value as a string.
123 124 125 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 123 def to_s @string || @object.to_s end |
#zero? ⇒ Boolean
Returns true
if the value is zero.
106 107 108 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/integer.rb', line 106 def zero? to_i.zero? end |