Sha256: 6f4da27aa29c941f3facdfdb50c275580f420d4a7eb37b768b3e7397f908b314

Contents?: true

Size: 1.41 KB

Versions: 35

Compression:

Stored size: 1.41 KB

Contents

module CV

  Param = Struct.new(:cv_ref, :accession, :name, :value, :unit)

  class Param

    # standard struct invocation.  Ensures that value is nil if an empty
    # string is given.
    def initialize(*args)
      args[3] = nil if (args[3] == '')
      super(*args)
    end

    # for now, assumes this is a Builder::XmlMarkup object.  
    # returns the xml builder object
    def to_xml(xml, name=:cvParam)
      hash_to_send = {:cvRef => self.cv_ref, :accession => self.accession, :name => self.name}
      if v=self.value
        hash_to_send[:value] = v
      end
      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

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



=begin
# if you want to use Nokogiri as the builder, you need something like this
# code:
class XML::Nokogiri::Builder
  def tag!(name, *data)
    send(name, *data)
  end
end
=end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
mspire-0.10.8.0 lib/cv/param.rb
mspire-0.10.7.3 lib/cv/param.rb
mspire-0.10.7.2 lib/cv/param.rb
mspire-0.10.7.1 lib/cv/param.rb
mspire-0.10.7 lib/cv/param.rb
mspire-0.10.6 lib/cv/param.rb
mspire-0.10.5 lib/cv/param.rb
mspire-0.10.4 lib/cv/param.rb
mspire-0.10.3 lib/cv/param.rb
mspire-0.10.2 lib/cv/param.rb
mspire-0.10.1 lib/cv/param.rb
mspire-0.10.0 lib/cv/param.rb
mspire-0.9.2 lib/cv/param.rb
mspire-0.9.1 lib/cv/param.rb
mspire-0.9.0 lib/cv/param.rb
mspire-0.8.7 lib/cv/param.rb
mspire-0.8.6.2 lib/cv/param.rb
mspire-0.8.6.1 lib/cv/param.rb
mspire-0.8.6 lib/cv/param.rb
mspire-0.8.5 lib/cv/param.rb