Module: RDF::Countable

Extended by:
Util::Aliasing::LateBound
Included in:
Enumerator, Dataset, Enumerable, Graph
Defined in:
lib/rdf/mixin/countable.rb,
lib/rdf/mixin/enumerator.rb

Overview

Since:

  • 0.2.0

Defined Under Namespace

Classes: Enumerator

Instance Method Summary collapse

Methods included from Util::Aliasing::LateBound

alias_method

Instance Method Details

#countInteger Also known as: size

Returns the number of RDF statements in ‘self`.

Returns:

  • (Integer)

Since:

  • 0.2.0



21
22
23
24
25
# File 'lib/rdf/mixin/countable.rb', line 21

def count
  count = 0
  each { count += 1 }
  count
end

#empty?Boolean

Returns ‘true` if `self` contains no RDF statements.

Returns:

  • (Boolean)

Since:

  • 0.2.0



12
13
14
15
# File 'lib/rdf/mixin/countable.rb', line 12

def empty?
  each {return false}
  true
end

#enum_for(method = :each, *args) ⇒ Enumerator Also known as: to_enum

Parameters:

  • method (Symbol, #to_sym) (defaults to: :each)

Returns:

See Also:

  • Object#enum_for

Since:

  • 0.2.0



33
34
35
36
37
38
39
# File 'lib/rdf/mixin/countable.rb', line 33

def enum_for(method = :each, *args)
  # Ensure that enumerators support the `#empty?` and `#count` methods:
  this = self
  Countable::Enumerator.new do |yielder|
    this.send(method, *args) {|y| yielder << y}
  end
end