Class: Report::Body::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/report/body/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &blk) ⇒ Column

Returns a new instance of Column.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/report/body/column.rb', line 10

def initialize(*args, &blk)
  if block_given?
    @blk = blk
  end
  @body = args.shift
  @name = args.shift
  options = args.extract_options!
  @method_id = options.delete(:method_id) || args.shift
  @faded = options.delete(:faded)
  @row_options = options
end

Instance Attribute Details

#blkObject (readonly)

Returns the value of attribute blk.



7
8
9
# File 'lib/report/body/column.rb', line 7

def blk
  @blk
end

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/report/body/column.rb', line 4

def body
  @body
end

#fadedObject (readonly)

Returns the value of attribute faded.



8
9
10
# File 'lib/report/body/column.rb', line 8

def faded
  @faded
end

#method_idObject (readonly)

Returns the value of attribute method_id.



6
7
8
# File 'lib/report/body/column.rb', line 6

def method_id
  @method_id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/report/body/column.rb', line 5

def name
  @name
end

#row_optionsObject (readonly)

Returns the value of attribute row_options.



9
10
11
# File 'lib/report/body/column.rb', line 9

def row_options
  @row_options
end

Instance Method Details

#read(report, obj) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/report/body/column.rb', line 21

def read(report, obj)
  if blk
    case blk.arity
    when 0
      obj.instance_eval(&blk)
    when 2
      blk.call report, obj
    else
      raise "column block should have 0 or 2 arguments"
    end
  elsif method_id
    obj.send method_id
  elsif from_name = guesses.detect { |m| obj.respond_to?(m) }
    obj.send from_name
  else
    raise "#{obj.inspect} does not respond to any of #{guesses.inspect}"
  end
end

#read_with_options(report, obj) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/report/body/column.rb', line 39

def read_with_options(report, obj)
  v = read report, obj
  f = case faded
  when Symbol
    obj.send faded
  else
    faded
  end
  { :value => v, :faded => f }.merge row_options
end