Class: Shades::QueryParser
- Inherits:
-
Object
- Object
- Shades::QueryParser
- Defined in:
- lib/shades/queryparser.rb
Class Method Summary collapse
- .categorizations_from_nodes(nodes) ⇒ Object
- .parse(qs, query_factory = Query) ⇒ Object
- .rollups_from_nodes(nodes) ⇒ Object
- .sorting_from_nodes(nodes) ⇒ Object
Class Method Details
.categorizations_from_nodes(nodes) ⇒ Object
84 85 86 87 88 |
# File 'lib/shades/queryparser.rb', line 84 def self.categorizations_from_nodes(nodes) nodes.map { |categorization| categorization.name } end |
.parse(qs, query_factory = Query) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/shades/queryparser.rb', line 60 def self.parse(qs, query_factory = Query) @parser_class ||= Treetop.load(File.join(File.dirname(__FILE__), "query.treetop")) parser = @parser_class.new unless query_node = parser.parse(qs) raise ArgumentError, "Cannot parse query at character #{parser.index}" end query_factory.new( :rollups => rollups_from_nodes(query_node.rollup_nodes), :categorizations => categorizations_from_nodes(query_node.categorization_nodes), :sorting => sorting_from_nodes(query_node.sorting_nodes) ) end |
.rollups_from_nodes(nodes) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/shades/queryparser.rb', line 75 def self.rollups_from_nodes(nodes) nodes.flat_map { |node| stat = Stats::StatsType.get(node.stat_type_name) node.measure_names.map { |measure_name| { :stat => stat, :measure => measure_name } } } end |
.sorting_from_nodes(nodes) ⇒ Object
90 91 92 93 94 |
# File 'lib/shades/queryparser.rb', line 90 def self.sorting_from_nodes(nodes) nodes.map { |sorting| { :key => sorting.name, :asc => true } } end |