Class: Rose::Seedling

Inherits:
Object
  • Object
show all
Defined in:
lib/rose/seedling.rb

Overview

Defines the Rose DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, options = {}) ⇒ Seedling

Returns a new instance of Seedling.

Parameters:

  • adapter (ObjectAdapter)

    An ObjectAdapter capable of sprouting a Seedling (running the report)

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :class (Class) — default: nil

    Used during by the adapter to enforce items types



25
26
27
28
29
# File 'lib/rose/seedling.rb', line 25

def initialize(adapter, options={})
  @adapter     = adapter
  @options     = options
  @alterations = @options[:alterations] = []
end

Instance Attribute Details

#adapterObjectAdapter (readonly)

Returns the adapter.

Returns:



13
14
15
# File 'lib/rose/seedling.rb', line 13

def adapter
  @adapter
end

#alterationsArray (readonly)

Returns the alterations to be applied to the sprouted Seedling (the report).

Returns:

  • (Array)

    the alterations to be applied to the sprouted Seedling (the report)



19
20
21
# File 'lib/rose/seedling.rb', line 19

def alterations
  @alterations
end

#optionsHash (readonly)

Returns the options used by the adapter.

Returns:

  • (Hash)

    the options used by the adapter



16
17
18
# File 'lib/rose/seedling.rb', line 16

def options
  @options
end

#rootRose::Proxy::Root (readonly)

Returns the root proxy containing attribute finder and updater.

Returns:



10
11
12
# File 'lib/rose/seedling.rb', line 10

def root
  @root
end

#rowRose::Proxy::Row (readonly)

Returns the row proxy containing an array of Attributes.

Returns:



7
8
9
# File 'lib/rose/seedling.rb', line 7

def row
  @row
end

Instance Method Details

#filter { ... } ⇒ Object

Yields:

  • Rose::Attribute::Filter



46
47
48
49
# File 'lib/rose/seedling.rb', line 46

def filter(&filter_block)
  @options[:filter] = Attribute::Filter.new(nil, nil, filter_block)
  @alterations << @options[:filter]
end

#pivot(group_column, pivot_column, &value_block) ⇒ Object

Parameters:

  • group_column (String, Symbol)

    the column to use for row data

  • pivot_column (String, Symbol)

    the column to use for column data

  • value_block (Proc)

    the block used to evalue the value data



63
64
65
66
# File 'lib/rose/seedling.rb', line 63

def pivot(group_column, pivot_column, &value_block)
  @options[:pivot] = Attribute::Pivot.new(group_column, pivot_column, value_block)
  @alterations << @options[:pivot]
end

#roots { ... } ⇒ Object

Yields:

  • Proxy::Root



69
70
71
72
73
# File 'lib/rose/seedling.rb', line 69

def roots(&blk)
  proxy = Proxy::Root.new
  proxy.instance_eval(&blk)
  @root = proxy
end

#rows { ... } ⇒ Object

Yields:

  • Proxy::Row



32
33
34
35
36
# File 'lib/rose/seedling.rb', line 32

def rows(&blk)
  proxy = Proxy::Row.new
  proxy.instance_eval(&blk)
  @row = proxy
end

#sort(column_name, order = :ascending, &sort_block) ⇒ Object

Parameters:

  • column_name (String, Symbol)

    the column to sort by

  • order (:ascending, :descending) (defaults to: :ascending)

    the order to sort by



40
41
42
43
# File 'lib/rose/seedling.rb', line 40

def sort(column_name, order = :ascending, &sort_block)
  @options[:sort] = Attribute::Sort.new(column_name, order, &sort_block)
  @alterations << @options[:sort]
end

#summary(column_name) { ... } ⇒ Object

Parameters:

  • column_name (String, Symbol)

    the column to group by

Yields:

  • Proxy::Summary



53
54
55
56
57
58
# File 'lib/rose/seedling.rb', line 53

def summary(column_name, &blk)
  proxy = Proxy::Summary.new(column_name)
  proxy.instance_eval(&blk)
  @options[:summary] = proxy
  @alterations << @options[:summary]
end