Class: Crosstab::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/crosstab/generic.rb

Direct Known Subclasses

Banner, Column, Crosstab, Row, Table

Instance Method Summary collapse

Instance Method Details

#printed?(value = nil) ⇒ Boolean

DSL accessor for the printed flag. Returns true if this object hasn’t been printed to the screen yet.

It’s just a useful flag when building a report (e.g., you can set printed? to true everytime you touch an object, and then you’ll know if you’ve printed a group already.)

Example:

printed?
# => false

printed? true
# => true

printed?
# => true

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'lib/crosstab/generic.rb', line 76

def printed?(value=nil)
  if value
    @printed = value
  else
    @printed ||= false
  end
end

#qualification(hash) ⇒ Object

Redefines the qualifies? test for this object

Example:

# By default, qualifies? always returns true.

qualifies? :a => 1
# => true

# But if we set it...
qualification :a => 2

# Then qualifies? returns false unless :a == 1
qualifies? :a => 1
# => false

qualifies? :a => 2
# => true


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/crosstab/generic.rb', line 42

def qualification(hash)
  @key, @value = *hash.to_a.first
  
  # Performance hack: improves overall benchmark from 1.37 to 0.96 by rendering the key and value inline.
  #                   Don't use any weird keys or values.  Stick to standard ruby library ones unless you know what you're doing.
  instance_eval %{
    def qualifies?(i)
      i[#{@key.inspect}] == #{@value.inspect}
    end
  }
end

#qualifies?(record) ⇒ Boolean

Returns true when a record passes the qualification filter.

This will always return true until set by qualification.

Returns:

  • (Boolean)


56
57
58
# File 'lib/crosstab/generic.rb', line 56

def qualifies?(record)
  true
end

#title(value = nil) ⇒ Object

DSL accessor for the title attribute

Example:

title
# => nil

title "Q.A Gender:"
# => "Q.A Gender:"

title
# => "Q.A Gender:"


15
16
17
18
19
20
21
# File 'lib/crosstab/generic.rb', line 15

def title(value=nil)
  if value
    @title = value
  else
    @title ||= nil
  end
end