Permalink
Browse files

Eliminate most warnings when running in debug mode

  • Loading branch information...
1 parent 6fee31b commit c61ef69c7614b7c956187afe911dd72579074853 @bernerdschaefer bernerdschaefer committed Oct 20, 2011
View
@@ -37,7 +37,7 @@ def read
while bits_left_in_chunk > 0 and @current_pos < @data.size
chunk = 0 if chunk.nil?
codepoint = @data[@current_pos, 1].unpack("C*")[0]
- current_byte = codepoint & (2**@bits_left_in_byte -1) #clear consumed bits
+ current_byte = codepoint & (2**@bits_left_in_byte - 1) #clear consumed bits
dif = bits_left_in_chunk - @bits_left_in_byte
if dif > 0 then current_byte <<= dif
elsif dif < 0 then current_byte >>= dif.abs
@@ -82,7 +82,7 @@ def add(string)
def self.decode(data)
stream = BitStream.new data.to_s, 9 # size of codes between 9 and 12 bits
result = ''
- while not (code = stream.read) == CODE_EOD
+ until (code = stream.read) == CODE_EOD
if code == CODE_CLEAR_TABLE
string_table = StringTable.new
code = stream.read
@@ -30,6 +30,7 @@ class ObjectHash
attr_accessor :default
attr_reader :trailer, :pdf_version
+ attr_reader :sec_handler
# Creates a new ObjectHash object. Input can be a string with a valid filename
# or an IO-like object.
@@ -104,8 +105,8 @@ def deref!(key)
case object = deref(key)
when Hash
- object.each do |key, value|
- object[key] = deref! value
+ object.each do |k, value|
+ object[k] = deref! value
end
when PDF::Reader::Stream
@@ -262,6 +263,10 @@ def encrypted?
trailer.has_key?(:Encrypt)
end
+ def sec_handler?
+ !!sec_handler
+ end
+
private
def build_security_handler(opts = {})
@@ -277,19 +282,19 @@ def build_security_handler(opts = {})
end
def decrypt(ref, obj)
- return obj if @sec_handler.nil?
+ return obj unless sec_handler?
case obj
when PDF::Reader::Stream then
- obj.data = @sec_handler.decrypt(obj.data, ref)
+ obj.data = sec_handler.decrypt(obj.data, ref)
obj
when Hash then
arr = obj.map { |key,val| [key, decrypt(ref, val)] }.flatten(1)
Hash[*arr]
when Array then
obj.collect { |item| decrypt(ref, item) }
when String
- @sec_handler.decrypt(obj, ref)
+ sec_handler.decrypt(obj, ref)
else
obj
end
@@ -350,7 +350,7 @@ def content_stream (instructions, fonts = {})
while (token = parser.parse_token(OPERATORS))
if token.kind_of?(Token) and OPERATORS.has_key?(token)
- if OPERATORS[token] == :set_text_font_and_size
+ if OPERATORS[token] == :set_text_font_and_size
current_font = params.first
if fonts[current_font].nil?
raise MalformedPDFError, "Unknown font #{current_font}"
View
@@ -130,7 +130,7 @@ def dictionary
# reads a PDF name from the buffer and converts it to a Ruby Symbol
def pdf_name
tok = @buffer.token
- tok.gsub! /#([A-Fa-f0-9]{2})/ do
+ tok.gsub!(/#([A-Fa-f0-9]{2})/) do
$1.hex.chr
end
tok.to_sym
View
@@ -108,7 +108,8 @@
else
bytes_per_pixel = bits / 8.0
end
- assert_equal (width * height * bytes_per_pixel).to_i, args[1].size
+ length = (width * height * bytes_per_pixel).to_i
+ assert_equal length, args[1].size
end
end
@@ -238,7 +239,7 @@
it "should return an array of Numbers and UTF-8 strings on #{filename}" do
receiver.all_args(:show_text_with_positioning).each do |args|
args[0].each do |arg|
- assert (arg.class == String || arg.class == Fixnum || arg.class == Float)
+ assert arg.class == String || arg.class == Fixnum || arg.class == Float
end
check_utf8(args)
end
View
@@ -254,18 +254,18 @@
callbacks = receiver.series(:begin_inline_image, :begin_inline_image_data, :end_inline_image)
# inline images should trigger 3 callbacks. The first with no args.
- callbacks[0].should == {:name => :begin_inline_image, :args => []}
+ callbacks[0].should eql(:name => :begin_inline_image, :args => [])
# the second with the image header (colorspace, etc)
- callbacks[1].should == {:name => :begin_inline_image_data, :args => [:CS, :RGB, :I, true, :W, 234, :H, 70, :BPC, 8]}
+ callbacks[1].should eql(:name => :begin_inline_image_data, :args => [:CS, :RGB, :I, true, :W, 234, :H, 70, :BPC, 8])
# the last with the image data
- callbacks[2][:name].should == :end_inline_image
+ callbacks[2][:name].should eql :end_inline_image
image_data = callbacks[2][:args].first
image_data.should be_a(String)
- image_data.size.should == 49140
- image_data[0,3].unpack("C*").should == [255,255,255]
- image_data[-3,3].unpack("C*").should == [255,255,255]
+ image_data.size.should eql 49140
+ image_data[0,3].unpack("C*").should eql [255,255,255]
+ image_data[-3,3].unpack("C*").should eql [255,255,255]
end
end
View
@@ -134,11 +134,11 @@
it "should parse numbers correctly" do
parser = parse_string("1 2 -3 4.5 -5")
- parser.parse_token.should == 1
- parser.parse_token.should == 2
- parser.parse_token.should == -3
- parser.parse_token.should == 4.5
- parser.parse_token.should == -5
+ parser.parse_token.should eql 1
+ parser.parse_token.should eql 2
+ parser.parse_token.should eql -3
+ parser.parse_token.should eql 4.5
+ parser.parse_token.should eql -5
end
end
View
@@ -55,18 +55,18 @@
info = PDF::Reader.new(oo3).info
info.size.should eql(3)
- info[:Creator].should == "Writer"
- info[:Producer].should == "OpenOffice.org 3.2"
- info[:CreationDate].should == "D:20101113071546-06'00'"
+ info[:Creator].should eql "Writer"
+ info[:Producer].should eql "OpenOffice.org 3.2"
+ info[:CreationDate].should eql "D:20101113071546-06'00'"
end
if RUBY_VERSION >= "1.9.2"
it "should return an info hash with strings marked as UTF-8" do
info = PDF::Reader.new(oo3).info
- info[:Creator].encoding.should == Encoding::UTF_8
- info[:Producer].encoding.should == Encoding::UTF_8
- info[:CreationDate].encoding.should == Encoding::UTF_8
+ info[:Creator].encoding.should eql Encoding::UTF_8
+ info[:Producer].encoding.should eql Encoding::UTF_8
+ info[:CreationDate].encoding.should eql Encoding::UTF_8
end
end
end
@@ -87,7 +87,7 @@
it "should return the metadata string marked as UTF-8" do
metadata = PDF::Reader.new(no_text_spaces).metadata
- metadata.encoding.should == Encoding::UTF_8
+ metadata.encoding.should eql Encoding::UTF_8
end
end
end

0 comments on commit c61ef69

Please sign in to comment.