Class: RECS4::XML::Elements

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/recs4/xml/elements.rb

Instance Method Summary collapse

Constructor Details

#initialize(elements_array) ⇒ Elements



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/recs4/xml/elements.rb', line 6

def initialize(elements_array)
  elements_array = elements_array.to_a
  unless elements_array.size > 0
    raise ArgumentError
  end
  elements_array.each do |e|
    unless e.is_a?(Element)
      raise ArgumentError
    end
  end
  @elements_array = elements_array
end

Instance Method Details

#[](element_name) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/recs4/xml/elements.rb', line 23

def [](element_name)
  if element_name.is_a?(Integer)
    index = element_name
    return @elements_array[index]
  else
    return @elements_array.first[element_name]
  end
end

#a(attribute_name) ⇒ Object



32
33
34
# File 'lib/recs4/xml/elements.rb', line 32

def a(attribute_name)
  return @elements_array.first.a(attribute_name)
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/recs4/xml/elements.rb', line 19

def each(&block)
  return @elements_array.each(&block)
end

#textObject



36
37
38
# File 'lib/recs4/xml/elements.rb', line 36

def text
  return @elements_array.first.text
end

#to_sObject



40
41
42
# File 'lib/recs4/xml/elements.rb', line 40

def to_s
  return @elements_array.first.to_s
end