Class: Opencdd::Parcel::Selector

Inherits:
Struct
  • Object
show all
Defined in:
lib/opencdd/parcel/selector.rb

Overview

Pure-data value object describing a parcel entity selection.

The Selector captures the intent of an export:

- +entities:+ — an Array of IRDIs (or entities) to include.
+nil+ means "every entity in the database".
- +closure:+ — whether to expand the entity set along the
class hierarchy. One of +:none+, +:ancestors+,
+:descendants+, or +:tree+ (both).

Resolution against a Opencdd::Database returns a flat Array<Opencdd::Entity> ordered by type (class, property, value_list, value_term, unit, relation, view_control). The caller (Writer, split, etc.) iterates and groups by type.

Cross-type lifting (declared properties, value_lists, relations, units) is +Database+'s responsibility; the selector only walks the class hierarchy and asks the database for cross-type dependencies.

Example:

sel = Opencdd::Parcel::Selector.new(entities: ["0112/2///61360_4#AAA001"], closure: :tree)
entities = sel.resolve(database)

Constant Summary collapse

CLOSURES =
%i[none ancestors descendants tree].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities: nil, closure: :none) ⇒ Selector

Returns a new instance of Selector.

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/opencdd/parcel/selector.rb', line 31

def initialize(entities: nil, closure: :none)
  raise ArgumentError, "invalid closure: #{closure.inspect}" unless CLOSURES.include?(closure)
  super(entities: entities, closure: closure)
end

Instance Attribute Details

#closureObject

Returns the value of attribute closure

Returns:

  • (Object)

    the current value of closure



28
29
30
# File 'lib/opencdd/parcel/selector.rb', line 28

def closure
  @closure
end

#entitiesObject

Returns the value of attribute entities

Returns:

  • (Object)

    the current value of entities



28
29
30
# File 'lib/opencdd/parcel/selector.rb', line 28

def entities
  @entities
end

Instance Method Details

#resolve(database) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/opencdd/parcel/selector.rb', line 36

def resolve(database)
  return database.entities.to_a if entities.nil? && closure == :none

  seed = expand_seed(database)
  expanded = apply_closure(database, seed)
  lift_cross_type(database, expanded)
end