Sha256: 824dfb6fbe378a08f0a9c10ef26f2adbd3d6d32c9e54fe0bf7b220a5ea4092b7

Contents?: true

Size: 752 Bytes

Versions: 8

Compression:

Stored size: 752 Bytes

Contents

class OctalInteger
  def self.from_xml(val)
    new(Integer(val.content))
  end

  def initialize(value)
    @val = value
  end

  def ==(other)
    @val == other
  end

  def to_xml
    sprintf("%#o", @val)
  end
end

class BookWithOctalPages
  include ROXML

  xml_accessor :pages_with_to_xml_proc, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
  xml_accessor :pages_with_type, OctalInteger, :required => true
end

class TestToXmlWithOverriddenOutput < Test::Unit::TestCase
  to_xml_test :book_with_octal_pages
  def test_padded_numbers_read_properly
    b = BookWithOctalPages.from_xml(fixture(:book_with_octal_pages))
    assert_equal 239, b.pages_with_type
    assert_equal 239, b.pages_with_to_xml_proc
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
Empact-roxml-2.4.0 test/unit/overriden_output_test.rb
Empact-roxml-2.4.1 test/unit/overriden_output_test.rb
Empact-roxml-2.4.2 test/unit/overriden_output_test.rb
Empact-roxml-2.4.3 test/unit/overriden_output_test.rb
roxml-2.4.0 test/unit/overriden_output_test.rb
roxml-2.4.2 test/unit/overriden_output_test.rb
roxml-2.4.1 test/unit/overriden_output_test.rb
roxml-2.4.3 test/unit/overriden_output_test.rb