Class: QueryFilters::Parser
- Inherits:
-
Object
- Object
- QueryFilters::Parser
- Extended by:
- Forwardable
- Defined in:
- lib/query_filters/parser.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ nesting_separator: ':', assignment_separator: '=', filters_separator: ',', symbolize_keys: true }.freeze
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(query, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ self
- #to_hash ⇒ Hash
Constructor Details
#initialize(query, options = {}) ⇒ Parser
Returns a new instance of Parser.
19 20 21 22 23 |
# File 'lib/query_filters/parser.rb', line 19 def initialize(query, = {}) @query = query @options = DEFAULT_OPTIONS.merge() parse end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
15 16 17 |
# File 'lib/query_filters/parser.rb', line 15 def filters @filters end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/query_filters/parser.rb', line 15 def @options end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
15 16 17 |
# File 'lib/query_filters/parser.rb', line 15 def query @query end |
Instance Method Details
#parse ⇒ self
26 27 28 29 30 31 |
# File 'lib/query_filters/parser.rb', line 26 def parse @filters = query_string.split([:filters_separator]).map do |filter| parse_filter(filter) end self end |
#to_hash ⇒ Hash
34 35 36 37 38 |
# File 'lib/query_filters/parser.rb', line 34 def to_hash filters_hash = {} filters.each { |filter| filters_hash.deep_merge!(filter) } filters_hash end |