Class: Sparrowhawk::War
- Inherits:
-
Object
- Object
- Sparrowhawk::War
- Defined in:
- lib/sparrowhawk/war.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #build ⇒ Object
- #exist? ⇒ Boolean (also: #exists?)
- #has_entry?(entry_name) ⇒ Boolean
-
#initialize(file_name = nil) ⇒ War
constructor
A new instance of War.
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
#entries ⇒ Object
Returns the value of attribute entries.
8 9 10 |
# File 'lib/sparrowhawk/war.rb', line 8 def entries @entries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/sparrowhawk/war.rb', line 7 def name @name end |
Instance Method Details
#build ⇒ Object
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?
15 16 17 |
# File 'lib/sparrowhawk/war.rb', line 15 def exist? File.exist? name end |
#has_entry?(entry_name) ⇒ 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 |