X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Feet.rb;h=95e1e469dd21307d61447169ed92536b877059d6;hb=deb555911974965cf23a4bcfdf79fb3b7d327663;hp=194409e4df9cbe8bf191f86e2812ee7f0adb2459;hpb=9bc23cbc321e908fd0761c40b3953574317f1131;p=ruby-eet.git diff --git a/lib/eet.rb b/lib/eet.rb index 194409e..95e1e46 100644 --- a/lib/eet.rb +++ b/lib/eet.rb @@ -1,5 +1,5 @@ #-- -# $Id: eet.rb 47 2005-05-30 19:19:07Z tilman $ +# $Id: eet.rb 60 2005-06-08 16:18:32Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -25,40 +25,6 @@ require "eet_ext" class Object - # :call-seq: - # object.to_eet -> string - # - # Serializes the receiver to EET format. - def to_eet - props = to_eet_properties - - unless props.is_a?(Hash) && !props.empty? - raise(Eet::PropertyError, "invalid EET properties") - end - - eet_name = to_eet_name - - if eet_name.to_str.length < 1 || eet_name.to_str.include?(0) - raise(Eet::NameError, "invalid EET name") - end - - stream = Eet::Stream.new - - props.each_pair do |tag, arg| - unless arg.is_a?(Array) - raise(Eet::PropertyError, "hash value is not an array") - end - - value, type = arg - next if value.nil? - - stream.push(*value.to_eet_chunks(tag, type)) - end - - chunk = Eet::Chunk.new(eet_name, stream.serialize) - Eet::Stream.new(chunk).serialize - end - def to_eet_chunks(tag, type = nil) # :nodoc: [Eet::Chunk.new(tag, to_eet)] end @@ -90,32 +56,6 @@ class Object end end -class Integer # :nodoc: - def to_eet_chunks(tag, type = nil) - fmt = case type - when :char: "c" - when :short: "v" - when :long_long: "q" - else "V" - end - - data = [self].pack(fmt) - [Eet::Chunk.new(tag, data)] - end -end - -class Float # :nodoc: - def to_eet_chunks(tag, type = nil) - fmt = case type - when :double: "%32.32f" - else "%16.16f" - end - - data = fmt % self - [Eet::Chunk.new(tag, data + "\0")] - end -end - class String # :nodoc: def to_eet_chunks(tag, type = nil) [Eet::Chunk.new(tag, self + "\0")] @@ -154,11 +94,8 @@ class Hash # :nodoc: end module Eet - VERSION = "0.1.2" + VERSION = "0.1.3" - class EetError < StandardError; end - class NameError < EetError; end - class PropertyError < EetError; end class ChunkError < EetError; end class Stream # :nodoc: