Class: Greeve::Rowset

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Helpers::AddAttribute
Defined in:
lib/greeve/rowset.rb

Overview

Represents an XML ‘rowset` element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, xml_element) { ... } ⇒ Rowset

Returns a new instance of Rowset.

Parameters:

  • name (Symbol)

    name of the rowset

  • xml_element (Ox::Element)

    the xml rowset element for this item

Yields:

  • a block containing the attribute definitions for Greeve::Row



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

def initialize(name, xml_element, &block)
  @name = name
  @xml_element = xml_element
  @attributes = {}
  @rows = nil

  # Load the attribute configuration in the rowset block.
  instance_eval(&block)

  # Disable the #attribute method since the attributes have been configured.
  define_singleton_method(:attribute) { raise NoMethodError, "private method" }
end

Instance Attribute Details

#nameSymbol (readonly)

Returns name of the rowset.

Returns:

  • (Symbol)

    name of the rowset



11
12
13
# File 'lib/greeve/rowset.rb', line 11

def name
  @name
end

Instance Method Details

#each(&block) ⇒ Object

:nodoc:



30
31
32
# File 'lib/greeve/rowset.rb', line 30

def each(&block)
  rows.each(&block)
end

#inspectObject

:nodoc:



40
41
42
# File 'lib/greeve/rowset.rb', line 40

def inspect
  "#<#{self.class.name}:#{object_id} name: #{@name}>"
end

#to_aArray

Returns an array of rows and their non-nil attributes.

Returns:

  • (Array)

    an array of rows and their non-nil attributes



35
36
37
# File 'lib/greeve/rowset.rb', line 35

def to_a
  map(&:to_h)
end