Class: Gitter::Axis
- Inherits:
-
Object
- Object
- Gitter::Axis
- Defined in:
- lib/gitter/axis.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#grid ⇒ Object
readonly
Returns the value of attribute grid.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #data ⇒ Object
- #data_titles ⇒ Object
-
#initialize(grid, name, opts = {}) ⇒ Axis
constructor
A new instance of Axis.
- #titles ⇒ Object
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
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
5 6 7 |
# File 'lib/gitter/axis.rb', line 5 def attr @attr end |
#grid ⇒ Object (readonly)
Returns the value of attribute grid.
5 6 7 |
# File 'lib/gitter/axis.rb', line 5 def grid @grid end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gitter/axis.rb', line 5 def name @name end |
Instance Method Details
#data ⇒ Object
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_titles ⇒ Object
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 |
#titles ⇒ Object
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 |