Class: Athena::Formats::XML

Inherits:
Base
  • Object
show all
Defined in:
lib/athena/formats/xml.rb

Direct Known Subclasses

Flat

Defined Under Namespace

Classes: BaseSpec, ElementSpec, Flat, RecordSpec, SubElementSpec

Constant Summary collapse

ELEMENT_START_RE =
%r{\A[a-zA-Z_:]}
NON_ELEMENT_CHAR_RE =
%r{[^\w:.-]}
VALUE_SEPARATOR =
'|'

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #output, #record_element

Instance Method Summary collapse

Methods inherited from Base

#deferred?, directions, format, has_direction?, init, #init, #run

Instance Attribute Details

#specsObject (readonly)

Returns the value of attribute specs.



47
48
49
# File 'lib/athena/formats/xml.rb', line 47

def specs
  @specs
end

Instance Method Details

#convert(record) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/athena/formats/xml.rb', line 54

def convert(record)
  builder.row {
    builder.id record.id

    record.struct.each { |field, struct|
      if block_given?
        yield field, struct
      else
        builder.tag!(field) {
          struct[:elements].each { |element|
            (struct[:values][element] || []).each { |value|
              value = (value || '').strip
              builder.tag!(element, value) unless value.empty?
            }
          }
        }
      end
    }
  }
end

#parse(input, &block) ⇒ Object



49
50
51
52
# File 'lib/athena/formats/xml.rb', line 49

def parse(input, &block)
  REXML::Document.parse_stream(input, listener(&block))
  Athena::Record.records.size
end

#raw?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/athena/formats/xml.rb', line 95

def raw?
  true
end