Sha256: 3cc93cd6388da0791c51d0995972e0125720f9a6dc4a6a2fd1af1b402f7040e6

Contents?: true

Size: 1.54 KB

Versions: 15

Compression:

Stored size: 1.54 KB

Contents

=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


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

    attr_accessor :cv_ref, :accession, :name, :value

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

    def initialize(cv_ref, accession, name, value=nil, unit=nil)
      @cv_ref, @accession, @name, @value, @unit = cv_ref, accession, name, value, unit
    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 => @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

    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
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mspire-0.7.5 lib/cv/param.rb
mspire-0.7.4 lib/cv/param.rb
mspire-0.7.3 lib/cv/param.rb
mspire-0.7.2 lib/cv/param.rb
mspire-0.6.26 lib/cv/param.rb
mspire-0.6.25 lib/cv/param.rb
mspire-0.6.24 lib/cv/param.rb
mspire-0.6.22 lib/cv/param.rb
mspire-0.6.21 lib/cv/param.rb
mspire-0.6.20 lib/cv/param.rb
mspire-0.6.19 lib/cv/param.rb
mspire-0.6.18 lib/cv/param.rb
mspire-0.6.12 lib/cv/param.rb
mspire-0.6.11 lib/cv/param.rb
mspire-0.6.9 lib/cv/param.rb