Class: MDQuery::Dataset::DimensionSegment
- Inherits:
-
Object
- Object
- MDQuery::Dataset::DimensionSegment
- Defined in:
- lib/mdquery/dataset.rb
Overview
describes a segment of a dimension, a segment being some part of the dimension value line. Dimension values should not be present in more than one segment of a dimension, or results will be unexpected, though it’s fine for aggregate values to be present which cover the same range as other values. e.g. having values of “jan”, “feb”, “march”… in one segment and “q1”,“q2”,“q3”,“q4” in another segment is fine
Instance Attribute Summary collapse
-
#dimension ⇒ Object
readonly
Dimension this Segment belongs to.
-
#dimension_values ⇒ Object
readonly
ordered list of DimensionValues in segment.
-
#key ⇒ Object
readonly
key of segment, unique within Dimension.
-
#values ⇒ Object
readonly
ordered list of all values in segment.
Instance Method Summary collapse
-
#[](value) ⇒ Object
retrieve a DimensionValue describing the given
value
. -
#dimension_value_for(value) ⇒ Object
retrieve a DimensionValue describing the given
value
. -
#initialize(model, dimension) ⇒ DimensionSegment
constructor
A new instance of DimensionSegment.
- #inspect ⇒ Object
-
#label_for(value) ⇒ Object
retrieve a label describing the given
value
. - #validate ⇒ Object
Constructor Details
#initialize(model, dimension) ⇒ DimensionSegment
Returns a new instance of DimensionSegment.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mdquery/dataset.rb', line 54 def initialize(model, dimension) @dimension = dimension @key = model.key @values = model.get_values(dimension.dataset.model.source) label_index = model.labels(@values) @dimension_values = @values.map{|v| DimensionValue.new(self, v, label_index[v]) } @dimension_value_index = @dimension_values.reduce({}){|dvi,dv| dvi[dv.value] = dv ; dvi} validate end |
Instance Attribute Details
#dimension ⇒ Object (readonly)
Dimension this Segment belongs to
43 44 45 |
# File 'lib/mdquery/dataset.rb', line 43 def dimension @dimension end |
#dimension_values ⇒ Object (readonly)
ordered list of DimensionValues in segment
49 50 51 |
# File 'lib/mdquery/dataset.rb', line 49 def dimension_values @dimension_values end |
#key ⇒ Object (readonly)
key of segment, unique within Dimension
46 47 48 |
# File 'lib/mdquery/dataset.rb', line 46 def key @key end |
#values ⇒ Object (readonly)
ordered list of all values in segment
52 53 54 |
# File 'lib/mdquery/dataset.rb', line 52 def values @values end |
Instance Method Details
#[](value) ⇒ Object
retrieve a DimensionValue describing the given value
83 84 85 |
# File 'lib/mdquery/dataset.rb', line 83 def [](value) dimension_value_for(value) end |
#dimension_value_for(value) ⇒ Object
retrieve a DimensionValue describing the given value
78 79 80 |
# File 'lib/mdquery/dataset.rb', line 78 def dimension_value_for(value) @dimension_value_index[value] end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/mdquery/dataset.rb', line 73 def inspect "#<DimensionSegment: key=#{key.inspect}, dimension_values=#{dimension_values.inspect}>" end |
#label_for(value) ⇒ Object
retrieve a label describing the given value
88 89 90 |
# File 'lib/mdquery/dataset.rb', line 88 def label_for(value) (dv = dimension_value_for(value)) && dv.label end |
#validate ⇒ Object
67 68 69 70 71 |
# File 'lib/mdquery/dataset.rb', line 67 def validate raise "no dimension!" if !dimension raise "no key!" if !key raise "no values!" if !values end |