Class: MarkdownComposer::SelectionResolver
- Inherits:
-
Object
- Object
- MarkdownComposer::SelectionResolver
- Defined in:
- lib/markdown_composer/selection_resolver.rb
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #include_units(unit, include_config) ⇒ Object
-
#initialize(index:, options: {}, diagnostics: Diagnostics.new, path: nil) ⇒ SelectionResolver
constructor
A new instance of SelectionResolver.
- #resolve(selector, within: nil) ⇒ Object
- #resolve_with_includes(selector, include_config) ⇒ Object
Constructor Details
#initialize(index:, options: {}, diagnostics: Diagnostics.new, path: nil) ⇒ SelectionResolver
Returns a new instance of SelectionResolver.
7 8 9 10 11 12 |
# File 'lib/markdown_composer/selection_resolver.rb', line 7 def initialize(index:, options: {}, diagnostics: Diagnostics.new, path: nil) @index = index @options = @diagnostics = diagnostics @path = path end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
5 6 7 |
# File 'lib/markdown_composer/selection_resolver.rb', line 5 def diagnostics @diagnostics end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'lib/markdown_composer/selection_resolver.rb', line 5 def index @index end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/markdown_composer/selection_resolver.rb', line 5 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/markdown_composer/selection_resolver.rb', line 5 def path @path end |
Instance Method Details
#include_units(unit, include_config) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/markdown_composer/selection_resolver.rb', line 33 def include_units(unit, include_config) included = [] excluded = [] Array(include_config).each do |item| if item["exclude"] excluded.concat(resolve_nested(unit, item["exclude"])) else included.concat(resolve_nested(unit, item)) end end (included - excluded).uniq(&:id).sort_by(&:source_position) end |
#resolve(selector, within: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/markdown_composer/selection_resolver.rb', line 14 def resolve(selector, within: nil) selector ||= { "type" => "all" } matches = if selector["types"] selector["types"].flat_map { |type| matches_for(type, within: within) }.uniq(&:id) else matches_for(selector["type"] || "all", within: within) end matches = apply_where(matches, selector["where"]) if selector["where"] matches = Take.apply(matches, selector["take"], diagnostics: diagnostics, path: path, seed: .fetch(:seed, 0)) if selector["take"] diagnostics.warn("selection.empty", "Selection matched no content", path: path) if matches.empty? matches end |
#resolve_with_includes(selector, include_config) ⇒ Object
27 28 29 30 31 |
# File 'lib/markdown_composer/selection_resolver.rb', line 27 def resolve_with_includes(selector, include_config) resolve(selector).flat_map do |unit| include_units(unit, include_config || [ { "type" => "all" } ]) end.uniq(&:id).sort_by(&:source_position) end |