class CqlRuby::FilterReader
Reads and provides filters.
Accepted filters and syntax:
Type:
type:(,[name])* example: type:def,send
Constants
- NESTING_ALLOWED_TYPES
Attributes
allowed_types[R]
@attribute [Array<Symbol>] allowed_types
has_leaves[R]
@attribute [Array<CqlRuby::FilterReader::NodeSpec>] has_leaves
is_assigned[R]
@attribute [Boolean] is_assigned
nest_under[R]
@attribute [Array<CqlRuby::FilterReader::NodeSpec>] nest_under
patterns[R]
@attribute [Array<CqlRuby::FilterReader::HierarchyPattern>] patterns
Public Class Methods
new(raw_filters = [])
click to toggle source
Calls superclass method
# File lib/cql_ruby/filter_reader.rb, line 73 def initialize(raw_filters = []) super() @allowed_types = [] @nest_under = [] @has_leaves = [] @patterns = [] @is_assigned = false parse_raw_filters(raw_filters) end
Public Instance Methods
restrict_assignment?()
click to toggle source
# File lib/cql_ruby/filter_reader.rb, line 101 def restrict_assignment? @is_assigned end
restrict_children?()
click to toggle source
# File lib/cql_ruby/filter_reader.rb, line 93 def restrict_children? !@has_leaves.empty? end
restrict_nesting?()
click to toggle source
# File lib/cql_ruby/filter_reader.rb, line 89 def restrict_nesting? !@nest_under.empty? end
restrict_pattern?()
click to toggle source
# File lib/cql_ruby/filter_reader.rb, line 97 def restrict_pattern? !@patterns.empty? end
restrict_types?()
click to toggle source
# File lib/cql_ruby/filter_reader.rb, line 85 def restrict_types? !@allowed_types.empty? end
Private Instance Methods
parse_raw_filters(raw_filters)
click to toggle source
@param [Array<String>] raw_filters
# File lib/cql_ruby/filter_reader.rb, line 108 def parse_raw_filters(raw_filters) raw_filters.each do |raw_filter| name, value = raw_filter.split(':') raise "Unrecognized filter: #{raw_filter}" if name.nil? if %w[type t].include?(name) @allowed_types += value.split(',').map(&:to_sym) elsif %w[nest n].include?(name) spec = NodeSpec.from(value) raise "Unknown type for nesting: '#{spec.type}' from '#{raw_filter}'. Allowed: #{NESTING_ALLOWED_TYPES}" unless NESTING_ALLOWED_TYPES.include?(spec.type) raise "Type #{spec.type} cannot have a name." if %w[block].include?(spec.type) && spec.restrict_name? @nest_under << spec elsif %w[has h].include?(name) @has_leaves << NodeSpec.from(value) elsif %w[pattern p].include?(name) @patterns << HierarchyPattern.from(value) elsif name == 'assigned' @is_assigned = true end end nil end