Class: Cubicle::Duration
- Defined in:
- lib/cubicle/duration.rb
Instance Attribute Summary collapse
-
#begin_milestone ⇒ Object
Returns the value of attribute begin_milestone.
-
#duration_unit ⇒ Object
Returns the value of attribute duration_unit.
-
#end_milestone ⇒ Object
Returns the value of attribute end_milestone.
-
#timestamp_prefix ⇒ Object
Returns the value of attribute timestamp_prefix.
Attributes inherited from Measure
Attributes inherited from Member
#alias_list, #expression_type, #field_name, #name, #options
Instance Method Summary collapse
- #condition ⇒ Object
- #default_aggregation_method ⇒ Object
- #expression ⇒ Object
-
#initialize(*args) ⇒ Duration
constructor
A new instance of Duration.
Methods inherited from Measure
#aggregate, #distinct_count?, #finalize_aggregation
Methods inherited from Member
#included_in?, #matches, #to_js_keys, #to_js_value
Constructor Details
#initialize(*args) ⇒ Duration
Returns a new instance of Duration.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cubicle/duration.rb', line 5 def initialize(*args) super self.duration_unit = (:in) || :seconds self. = :timestamp_prefix, :prefix self.expression_type = :javascript #only one item should be left in the hash, the duration map raise "duration must be provided with a hash with a single entry, where the key represents the starting milestone of a duration and the value represents the ending milestone." if .length != 1 self.begin_milestone, self.end_milestone = .to_a[0] self.name ||= "#{begin_milestone}_to_#{end_milestone}_#{aggregation_method}".to_sym end |
Instance Attribute Details
#begin_milestone ⇒ Object
Returns the value of attribute begin_milestone.
3 4 5 |
# File 'lib/cubicle/duration.rb', line 3 def begin_milestone @begin_milestone end |
#duration_unit ⇒ Object
Returns the value of attribute duration_unit.
3 4 5 |
# File 'lib/cubicle/duration.rb', line 3 def duration_unit @duration_unit end |
#end_milestone ⇒ Object
Returns the value of attribute end_milestone.
3 4 5 |
# File 'lib/cubicle/duration.rb', line 3 def end_milestone @end_milestone end |
#timestamp_prefix ⇒ Object
Returns the value of attribute timestamp_prefix.
3 4 5 |
# File 'lib/cubicle/duration.rb', line 3 def @timestamp_prefix end |
Instance Method Details
#condition ⇒ Object
21 22 23 24 |
# File 'lib/cubicle/duration.rb', line 21 def condition cond = " && (#{super})" unless super.blank? "#{milestone_js(:begin)} && #{milestone_js(:end)}#{cond}" end |
#default_aggregation_method ⇒ Object
17 18 19 |
# File 'lib/cubicle/duration.rb', line 17 def default_aggregation_method :average end |
#expression ⇒ Object
26 27 28 29 30 31 |
# File 'lib/cubicle/duration.rb', line 26 def expression #prefix these names for the expression # prefix = "#{self.timestamp_prefix}#{self.timestamp_prefix.blank? ? '' : '.'}" # ms1,ms2 = [self.begin_milestone,self.end_milestone].map{|ms|ms.to_s=='now' ? "new Date(#{Time.now.to_i*1000})" : "this.#{prefix}#{ms}"} @expression = "(#{milestone_js(:end)}-#{milestone_js(:begin)})/#{denominator}" end |