Class: Tableize::ColumnBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tableize/column_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, *args, &block) ⇒ ColumnBuilder

Returns a new instance of ColumnBuilder.



6
7
8
9
10
11
12
13
# File 'lib/tableize/column_builder.rb', line 6

def initialize(resource_class, *args, &block)
  @options        = args.extract_options!
  @resource_class = resource_class
  @html_options   = @options.delete(:html) || {}
  @block          = block
  @title          = get_title(args)
  @method         = get_method(args)
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/tableize/column_builder.rb', line 4

def method
  @method
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/tableize/column_builder.rb', line 4

def title
  @title
end

Instance Method Details

#td_optionsObject



29
30
31
# File 'lib/tableize/column_builder.rb', line 29

def td_options
  get_options(:td)
end

#th_optionsObject



33
34
35
36
37
38
39
40
41
# File 'lib/tableize/column_builder.rb', line 33

def th_options
  options = get_options(:th)

  if @method
    options[:class] = Tableize::convert_to_array(options[:class], @method.to_s.underscore, value_type)
  end

  options
end

#value(resource, extras) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tableize/column_builder.rb', line 15

def value(resource, extras)
  if @block
    @method ? @block.call(resource.send(@method), *extras) : @block.call(resource, *extras)
  else
    if @method
      if resource.respond_to?(@method)
        resource.send(@method)
      elsif resource.kind_of?(Hash)
        resource[@method]
      end
    end
  end
end