Class: Rorschart::PivotData

Inherits:
Object
  • Object
show all
Defined in:
lib/rorschart/pivot_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ PivotData

Returns a new instance of PivotData.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rorschart/pivot_data.rb', line 7

def initialize(raw_data)

    data = convert_objects_to_array_of_hash(raw_data)
    data = data.to_pivot if data.is_a? Rorschart::MultipleSeries

    case data
    when Array          
      case data.first     
      when Array
        cols = columns_from_array_row(data.first)
      when Hash
        cols = columns_from_hash_row(data)
        data = data.map{|row| row.values}
      end
    when Hash
      cols = columns_from_array_row(data.first)     
    end

    @rows = data.to_a
    @cols = cols
end

Instance Attribute Details

#colsObject

Returns the value of attribute cols.



5
6
7
# File 'lib/rorschart/pivot_data.rb', line 5

def cols
  @cols
end

#rowsObject

Returns the value of attribute rows.



5
6
7
# File 'lib/rorschart/pivot_data.rb', line 5

def rows
  @rows
end

Instance Method Details

#sort_by_date!Object



29
30
31
32
33
34
35
# File 'lib/rorschart/pivot_data.rb', line 29

def sort_by_date!

  if ['datetime', 'date'].include? @cols.first[:type]
    @rows.sort!
  end

end