Class: RDF::Literal::Integer
- Inherits:
-
Decimal
- Object
- RDF::Literal
- Decimal
- RDF::Literal::Integer
- Includes:
- Numeric
- Defined in:
- lib/rdf/model/literal/integer.rb
Overview
An integer literal.
Constant Summary
- DATATYPE =
XSD.integer
- GRAMMAR =
/^[\+\-]?\d+$/.freeze
Constants inherited from Decimal
Constants inherited from RDF::Literal
Instance Method Summary (collapse)
-
- (RDF::Literal) *(other)
Returns the product of
selftimesother. -
- (RDF::Literal) +(other)
Returns the sum of
selfplusother. -
- (RDF::Literal) +@
Returns
self. -
- (RDF::Literal) -(other)
Returns the difference of
selfminusother. -
- (RDF::Literal) -@
Returns
selfnegated. -
- (RDF::Literal) /(other)
Returns the quotient of
selfdivided byother. -
- (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. -
- (BigDecimal) to_d
Returns the value as a decimal number.
-
- (Float) to_f
Returns the value as a floating point number.
-
- (Integer) to_i
(also: #ord, #to_int)
Returns the value as an integer.
-
- (Rational) to_r
Returns the value as a rational number.
-
- (String) to_s
Returns the value as a string.
-
- (Boolean) zero?
Returns
trueif the value is zero.
Methods inherited from Decimal
Methods inherited from RDF::Literal
#==, #anonymous?, #canonicalize, #eql?, #has_datatype?, #has_language?, #hash, #inspect, #invalid?, #literal?, #object, #valid?, #validate!, #value
Methods included from Term
Methods included from Value
#graph?, #inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #statement?, #to_ntriples, #to_rdf, #uri?, #variable?
Constructor Details
- (Integer) initialize(value, options = {})
A new instance of Integer
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rdf/model/literal/integer.rb', line 22 def initialize(value, = {}) @datatype = RDF::URI([:datatype] || DATATYPE) @string = [:lexical] if .has_key?(:lexical) @string = value if !defined?(@string) && 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) *(other)
Returns the product of self times other.
152 153 154 |
# File 'lib/rdf/model/literal/integer.rb', line 152 def *(other) RDF::Literal(to_i * other.to_i) end |
- (RDF::Literal) +(other)
Returns the sum of self plus other.
132 133 134 |
# File 'lib/rdf/model/literal/integer.rb', line 132 def +(other) RDF::Literal(to_i + other.to_i) end |
- (RDF::Literal) +@
Returns self.
113 114 115 |
# File 'lib/rdf/model/literal/integer.rb', line 113 def +@ self # unary plus end |
- (RDF::Literal) -(other)
Returns the difference of self minus other.
142 143 144 |
# File 'lib/rdf/model/literal/integer.rb', line 142 def -(other) RDF::Literal(to_i - other.to_i) end |
- (RDF::Literal) -@
Returns self negated.
122 123 124 |
# File 'lib/rdf/model/literal/integer.rb', line 122 def -@ RDF::Literal(-to_i) # unary minus end |
- (RDF::Literal) /(other)
Returns the quotient of self divided by other.
163 164 165 |
# File 'lib/rdf/model/literal/integer.rb', line 163 def /(other) RDF::Literal(to_i / other.to_i) end |
- (RDF::Literal) abs
Returns the absolute value of self.
86 87 88 |
# File 'lib/rdf/model/literal/integer.rb', line 86 def abs (n = to_i) && n > 0 ? self : RDF::Literal(n.abs) end |
- (RDF::Literal) canonicalize!
Converts this literal into its canonical lexical representation.
39 40 41 42 |
# File 'lib/rdf/model/literal/integer.rb', line 39 def canonicalize! @string = @object.to_s if @object self end |
- (Boolean) even?
Returns true if the value is even.
68 69 70 |
# File 'lib/rdf/model/literal/integer.rb', line 68 def even? to_i.even? end |
- (Boolean) nonzero?
Returns self if the value is not zero, nil otherwise.
104 105 106 |
# File 'lib/rdf/model/literal/integer.rb', line 104 def nonzero? to_i.nonzero? ? self : nil end |
- (Boolean) odd?
Returns true if the value is odd.
77 78 79 |
# File 'lib/rdf/model/literal/integer.rb', line 77 def odd? to_i.odd? end |
- (RDF::Literal) pred
Returns the successor value of self.
49 50 51 |
# File 'lib/rdf/model/literal/integer.rb', line 49 def pred RDF::Literal(to_i.pred) end |
- (RDF::Literal) succ Also known as: next
Returns the predecessor value of self.
58 59 60 |
# File 'lib/rdf/model/literal/integer.rb', line 58 def succ RDF::Literal(to_i.succ) end |
- (OpenSSL::BN) to_bn
Returns the value as an OpenSSL::BN instance.
215 216 217 218 |
# File 'lib/rdf/model/literal/integer.rb', line 215 def to_bn require 'openssl' unless defined?(OpenSSL::BN) OpenSSL::BN.new(to_s) end |
- (BigDecimal) to_d
Returns the value as a decimal number.
197 198 199 |
# File 'lib/rdf/model/literal/integer.rb', line 197 def to_d @object.respond_to?(:to_d) ? @object.to_d : BigDecimal(@object.to_s) end |
- (Float) to_f
Returns the value as a floating point number.
189 190 191 |
# File 'lib/rdf/model/literal/integer.rb', line 189 def to_f @object.to_f end |
- (Integer) to_i Also known as: ord, to_int
Returns the value as an integer.
179 180 181 |
# File 'lib/rdf/model/literal/integer.rb', line 179 def to_i @object.to_i end |
- (Rational) to_r
Returns the value as a rational number.
205 206 207 |
# File 'lib/rdf/model/literal/integer.rb', line 205 def to_r @object.to_r end |
- (String) to_s
Returns the value as a string.
171 172 173 |
# File 'lib/rdf/model/literal/integer.rb', line 171 def to_s @string || @object.to_s end |
- (Boolean) zero?
Returns true if the value is zero.
95 96 97 |
# File 'lib/rdf/model/literal/integer.rb', line 95 def zero? to_i.zero? end |