Class: CV::Param

Inherits:
Object
  • Object
show all
Defined in:
lib/cv/param.rb

Overview

the xml writer is written with the assumption that the object is a Builder::XmlMarkup object. You can get away with using Nokogiri

Direct Known Subclasses

Mspire::CV::Param

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cv_ref, accession, name, value = nil, unit = nil) ⇒ Param

Returns a new instance of Param.



22
23
24
# File 'lib/cv/param.rb', line 22

def initialize(cv_ref, accession, name, value=nil, unit=nil)
  @cv_ref, @accession, @name, @value, @unit = cv_ref, accession, name, value, unit
end

Instance Attribute Details

#accessionObject

Returns the value of attribute accession.



17
18
19
# File 'lib/cv/param.rb', line 17

def accession
  @accession
end

#cv_refObject

Returns the value of attribute cv_ref.



17
18
19
# File 'lib/cv/param.rb', line 17

def cv_ref
  @cv_ref
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/cv/param.rb', line 17

def name
  @name
end

#unitObject

A valueless CV::Param object that describes the units being used



20
21
22
# File 'lib/cv/param.rb', line 20

def unit
  @unit
end

#valueObject

Returns the value of attribute value.



17
18
19
# File 'lib/cv/param.rb', line 17

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/cv/param.rb', line 44

def ==(other)
  if !other.nil? && other.is_a?(CV::Param)
    [:cv_ref, :accession, :name, :value, :unit].inject(true) do |bool, mthd|
      bool && (self.send(mthd) == other.send(mthd))
    end
  else ; false
  end
end

#to_xml(xml, name = :cvParam) ⇒ Object

for now, assumes this is a Builder::XmlMarkup object.

returns the xml builder object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cv/param.rb', line 28

def to_xml(xml, name=:cvParam)
  hash_to_send = {:cvRef => @cv_ref, :accession => @accession, :name => @name}
  hash_to_send[:value] = @value if @value
  if unit
    hash_to_send.merge!( { :unitCvRef => unit.cv_ref, 
                        :unitAccession => unit.accession,
                        :unitName => unit.name } )
  end

  # xml.send for builder results in tags with 'send' in the front
  xml.tag!(name, hash_to_send)
  # for nokogiri builder
  #xml.send(name, hash_to_send)
  xml
end