Class: Greeve::Row

Inherits:
Object
  • Object
show all
Includes:
Helpers::AttributeToHash, Helpers::DefineDSLMethods
Defined in:
lib/greeve/row.rb

Overview

Represents an XML ‘row` element, contained in a Rowset.

Instance Method Summary collapse

Methods included from Helpers::AttributeToHash

#to_h

Constructor Details

#initialize(xml_element, attributes) ⇒ Row

Returns a new instance of Row.

Parameters:

  • xml_element (Ox::Element)

    the xml row element for this item

  • attributes (Hash)

    the hash of attribute definitions for this row



12
13
14
15
16
17
18
19
# File 'lib/greeve/row.rb', line 12

def initialize(xml_element, attributes)
  @xml_element = xml_element
  @attributes = attributes

  attributes.each do |name, opts|
    define_attribute_method(:instance, name, opts)
  end
end

Instance Method Details

#inspectObject

:nodoc:



22
23
24
25
26
27
28
29
30
31
# File 'lib/greeve/row.rb', line 22

def inspect
  attrs = to_s

  unless attrs.empty?
    attrs = attrs.split("\n").map { |l| "  #{l}" }.join("\n")
    attrs = "\n#{attrs}\n"
  end

  "#<#{self.class.name}:#{object_id}#{attrs}>"
end

#to_sString

Returns a string representation of the non-nil attributes.

Returns:

  • (String)

    a string representation of the non-nil attributes



34
35
36
37
38
39
40
41
# File 'lib/greeve/row.rb', line 34

def to_s
  to_h
    .map { |k, v|
      v = v.to_s("F") if v.is_a?(BigDecimal)
      "#{k}: #{v}"
    }
    .join("\n")
end