Class: PutText::POFile

Inherits:
Object
  • Object
show all
Defined in:
lib/puttext/po_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ POFile

Create a new POFile

Parameters:

  • entries (Array<POEntry>)

    an array of POEntry objects, that should be placed in this file.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/puttext/po_file.rb', line 13

def initialize(entries)
  @entries = entries

  now = Time.now.strftime('%Y-%m-%d %H:%M%z')

  @header_entry = POEntry.new(
    flags: ['fuzzy'],
    msgid: '',
    msgstr: "      POT-Creation-Date: \#{now}\n      MIME-Version: 1.0\n      Content-Type: text/plain; charset=UTF-8\n    STRING\n  )\nend\n".unindent

Instance Attribute Details

#entriesObject

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



48
49
50
# File 'lib/puttext/po_file.rb', line 48

def ==(other)
  @entries.sort == other.entries.sort
end

#to_sObject



29
30
31
32
33
# File 'lib/puttext/po_file.rb', line 29

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.

Parameters:

  • io (IO)

    the IO object to write the contents of the file to.



37
38
39
40
41
42
43
44
45
46
# File 'lib/puttext/po_file.rb', line 37

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