Class: PutText::POFile
- Inherits:
-
Object
- Object
- PutText::POFile
- Defined in:
- lib/puttext/po_file.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(entries) ⇒ POFile
constructor
Create a new POFile.
-
#merge(other_file) ⇒ Object
Merge the contents of another POFile to this POFile.
- #to_s ⇒ Object
-
#write_to(io) ⇒ Object
Write the contents of this file to the specified IO object.
Constructor Details
#initialize(entries) ⇒ POFile
Create a new POFile
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puttext/po_file.rb', line 13 def initialize(entries) @entries = entries @header_entry = POEntry.new( flags: ['fuzzy'], msgid: '', msgstr: <<-STRING.unindent POT-Creation-Date: #{Time.now.strftime('%Y-%m-%d %H:%M%z')} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 STRING ) end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
8 9 10 |
# File 'lib/puttext/po_file.rb', line 8 def entries @entries end |
Instance Method Details
#==(other) ⇒ Object
55 56 57 |
# File 'lib/puttext/po_file.rb', line 55 def ==(other) @entries.sort == other.entries.sort end |
#merge(other_file) ⇒ Object
Merge the contents of another POFile to this POFile.
47 48 49 50 51 52 53 |
# File 'lib/puttext/po_file.rb', line 47 def merge(other_file) unless other_file.is_a?(POFile) raise ArgumentError, 'argument must be a PutText::POFile' end @entries += other_file.entries end |
#to_s ⇒ Object
26 27 28 29 30 |
# File 'lib/puttext/po_file.rb', line 26 def to_s str_io = StringIO.new write_to(str_io) str_io.string end |
#write_to(io) ⇒ Object
Write the contents of this file to the specified IO object.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puttext/po_file.rb', line 34 def write_to(io) deduplicate io.write(@header_entry.to_s) @entries.each do |entry| io.write("\n") io.write(entry.to_s) end end |