Class: Greeve::Namespace

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

Overview

Contains a group of attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::AttributeToHash

#to_h

Constructor Details

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

Returns a new instance of Namespace.

Parameters:

  • name (Symbol)

    name of the namespace

  • xml_element (Ox::Element)

    the xml namespace element for this item

Yields:

  • a block containing the attribute definitions



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/greeve/namespace.rb', line 18

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

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

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

Instance Attribute Details

#nameSymbol (readonly)

Returns name of the namespace.

Returns:

  • (Symbol)

    name of the namespace



13
14
15
# File 'lib/greeve/namespace.rb', line 13

def name
  @name
end

Instance Method Details

#inspectObject

:nodoc:



32
33
34
35
36
# File 'lib/greeve/namespace.rb', line 32

def inspect
  attrs = to_s.lines[1..-1].join

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

#to_sString

Returns a string representation of the non-nil attributes.

Returns:

  • (String)

    a string representation of the non-nil attributes



39
40
41
42
43
44
45
46
47
# File 'lib/greeve/namespace.rb', line 39

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