Class: Sparrowhawk::War

Inherits:
Object
  • Object
show all
Defined in:
lib/sparrowhawk/war.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name = nil) ⇒ War

Returns a new instance of War.



10
11
12
13
# File 'lib/sparrowhawk/war.rb', line 10

def initialize file_name=nil
  @name = file_name || default_file_name
  @entries = []
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



8
9
10
# File 'lib/sparrowhawk/war.rb', line 8

def entries
  @entries
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/sparrowhawk/war.rb', line 7

def name
  @name
end

Instance Method Details

#buildObject



25
26
27
28
29
30
31
32
# File 'lib/sparrowhawk/war.rb', line 25

def build
  open_war for_writing do |zip|
    entries.flatten.each do |entry|
      zip.file.open(entry.name, "w") { |f| f << entry.content }
    end
  end
  self
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


15
16
17
# File 'lib/sparrowhawk/war.rb', line 15

def exist?
  File.exist? name
end

#has_entry?(entry_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/sparrowhawk/war.rb', line 20

def has_entry? entry_name
  return false unless exists?
  open_war { |zip| zip.file.exists?(entry_name) }
end