Class: Aggregate
- Inherits:
-
Object
- Object
- Aggregate
- Defined in:
- lib/aggregate.rb
Instance Attribute Summary collapse
-
#aggs ⇒ Object
Returns the value of attribute aggs.
-
#dimension ⇒ Object
Returns the value of attribute dimension.
-
#item ⇒ Object
Returns the value of attribute item.
Class Method Summary collapse
-
.parse(agg_doc) ⇒ Object
parse the nokogiri doc and extract the aggregation properties it contains.
Instance Method Summary collapse
Instance Attribute Details
#aggs ⇒ Object
Returns the value of attribute aggs.
4 5 6 |
# File 'lib/aggregate.rb', line 4 def aggs @aggs end |
#dimension ⇒ Object
Returns the value of attribute dimension.
4 5 6 |
# File 'lib/aggregate.rb', line 4 def dimension @dimension end |
#item ⇒ Object
Returns the value of attribute item.
4 5 6 |
# File 'lib/aggregate.rb', line 4 def item @item end |
Class Method Details
.parse(agg_doc) ⇒ Object
parse the nokogiri doc and extract the aggregation properties it contains
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aggregate.rb', line 15 def self.parse(agg_doc) a = self.new # extract the item and dimension names [:item, :dimension].each do |arg| agg_doc.css(".#{arg.to_s}").each { |elem| a.send("#{arg.to_s}=", elem.inner_text) } end # extract aggregation values and the associated types (functions) a.aggs = [];agg_doc.css('.aggs > .func').each do |vs| dimension_type = vs[:class].gsub(/func /,'') dimension_value = vs.inner_text a.aggs << {:function=> dimension_type, :value => dimension_value} end #puts "aggregation object : #{a.aggs.to_s}" return a end |
Instance Method Details
#to_h ⇒ Object
10 11 12 |
# File 'lib/aggregate.rb', line 10 def to_h {:dimension =>@dimension, :item=>@item, :aggs=>@aggs } end |
#to_json ⇒ Object
6 7 8 |
# File 'lib/aggregate.rb', line 6 def to_json to_h.to_json end |