Class: Gitter::Axis

Inherits:
Object
  • Object
show all
Defined in:
lib/gitter/axis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grid, name, opts = {}) ⇒ Axis

Returns a new instance of Axis.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gitter/axis.rb', line 7

def initialize grid, name, opts = {}
  @grid, @name = grid, name
  @attr = opts.delete(:column){name}
  only = opts.delete(:only){nil}
  case only
  when Hash
    @only_data, @titles= only.keys, only
  else
    @only_data, @titles = only, nil
  end
  @except = opts.delete(:except){[]}
end

Instance Attribute Details

#attrObject (readonly)

Returns the value of attribute attr.



5
6
7
# File 'lib/gitter/axis.rb', line 5

def attr
  @attr
end

#gridObject (readonly)

Returns the value of attribute grid.



5
6
7
# File 'lib/gitter/axis.rb', line 5

def grid
  @grid
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gitter/axis.rb', line 5

def name
  @name
end

Instance Method Details

#dataObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitter/axis.rb', line 21

def data
  data = case attr
  when Symbol,String
    grid.scope.select(attr).uniq.map(&:"#{attr}").sort
  else
    attr
  end

  data = ((data + @only_data) & @only_data).uniq if @only_data
  data = data - @except
end

#data_titlesObject



41
42
43
44
45
# File 'lib/gitter/axis.rb', line 41

def data_titles
  res = {}	   
  data.each{|d| res[d] = @titles ? @titles[d] : d}
  res
end

#titlesObject



33
34
35
36
37
38
39
# File 'lib/gitter/axis.rb', line 33

def titles
  if @titles
    data.map{|d|@titles[d]}
  else
    data
  end
end