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.



10
11
12
# File 'lib/puttext/po_file.rb', line 10

def initialize(entries)
  @entries = entries
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



5
6
7
# File 'lib/puttext/po_file.rb', line 5

def entries
  @entries
end

Instance Method Details

#==(other) ⇒ Object



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

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

#to_sObject



14
15
16
17
18
# File 'lib/puttext/po_file.rb', line 14

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.



22
23
24
25
26
27
28
29
# File 'lib/puttext/po_file.rb', line 22

def write_to(io)
  deduplicate

  @entries.each_with_index do |entry, index|
    io.write("\n") unless index == 0
    io.write(entry.to_s)
  end
end