Class: Greeve::Rowset

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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



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

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



9
10
11
# File 'lib/greeve/rowset.rb', line 9

def name
  @name
end

Instance Method Details

#each(&block) ⇒ Object

:nodoc:



28
29
30
# File 'lib/greeve/rowset.rb', line 28

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

#inspectObject

:nodoc:



38
39
40
# File 'lib/greeve/rowset.rb', line 38

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



33
34
35
# File 'lib/greeve/rowset.rb', line 33

def to_a
  map(&:to_h)
end