Class: Opencdd::Parcel::Selector
- Inherits:
-
Struct
- Object
- Struct
- Opencdd::Parcel::Selector
- 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
-
#closure ⇒ Object
Returns the value of attribute closure.
-
#entities ⇒ Object
Returns the value of attribute entities.
Instance Method Summary collapse
-
#initialize(entities: nil, closure: :none) ⇒ Selector
constructor
A new instance of Selector.
- #resolve(database) ⇒ Object
Constructor Details
#initialize(entities: nil, closure: :none) ⇒ Selector
Returns a new instance of Selector.
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
#closure ⇒ Object
Returns the value of attribute closure
28 29 30 |
# File 'lib/opencdd/parcel/selector.rb', line 28 def closure @closure end |
#entities ⇒ Object
Returns the value of attribute 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 = (database) = apply_closure(database, seed) lift_cross_type(database, ) end |