Class: PutText::POEntry
- Inherits:
-
Object
- Object
- PutText::POEntry
- Defined in:
- lib/puttext/po_entry.rb
Constant Summary collapse
- NS_SEPARATOR =
'|'.freeze
- PO_C_STYLE_ESCAPES =
{ "\n" => '\\n', "\r" => '\\r', "\t" => '\\t', '\\' => '\\\\', '"' => '\\"' }.freeze
Instance Attribute Summary collapse
-
#msgctxt ⇒ Object
readonly
Returns the value of attribute msgctxt.
-
#msgid ⇒ Object
readonly
Returns the value of attribute msgid.
-
#msgid_plural ⇒ Object
readonly
Returns the value of attribute msgid_plural.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(attrs) ⇒ POEntry
constructor
Create a new POEntry.
-
#merge(other_entry) ⇒ POEntry
Merge this entry with another entry.
-
#plural? ⇒ Boolean
Check if the entry has a plural form.
-
#references? ⇒ Boolean
Check if the entry has any references.
-
#to_s ⇒ String
Convert the entry to a string representation, to be written to a .po file.
-
#unique_key ⇒ Object
Return an object uniquely identifying this entry.
Constructor Details
#initialize(attrs) ⇒ POEntry
Create a new POEntry
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puttext/po_entry.rb', line 33 def initialize(attrs) id, ctx = extract_context( attrs[:msgid], attrs[:separator] || NS_SEPARATOR ) @msgid = id @msgctxt = attrs[:msgctxt] || ctx @msgid_plural = attrs[:msgid_plural] @references = attrs[:references] || [] end |
Instance Attribute Details
#msgctxt ⇒ Object (readonly)
Returns the value of attribute msgctxt.
17 18 19 |
# File 'lib/puttext/po_entry.rb', line 17 def msgctxt @msgctxt end |
#msgid ⇒ Object (readonly)
Returns the value of attribute msgid.
15 16 17 |
# File 'lib/puttext/po_entry.rb', line 15 def msgid @msgid end |
#msgid_plural ⇒ Object (readonly)
Returns the value of attribute msgid_plural.
16 17 18 |
# File 'lib/puttext/po_entry.rb', line 16 def msgid_plural @msgid_plural end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
18 19 20 |
# File 'lib/puttext/po_entry.rb', line 18 def references @references end |
Instance Method Details
#==(other) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/puttext/po_entry.rb', line 91 def ==(other) @msgid == other.msgid && @msgid_plural == other.msgid_plural && @msgctxt == other.msgctxt && @references == other.references end |
#merge(other_entry) ⇒ POEntry
Merge this entry with another entry. Modifies the current entry in place. Currently, merges only the references, and leaves other attributes of the current entry untouched.
86 87 88 89 |
# File 'lib/puttext/po_entry.rb', line 86 def merge(other_entry) @references += other_entry.references self end |
#plural? ⇒ Boolean
Check if the entry has a plural form.
69 70 71 |
# File 'lib/puttext/po_entry.rb', line 69 def plural? !@msgid_plural.nil? end |
#references? ⇒ Boolean
Check if the entry has any references.
63 64 65 |
# File 'lib/puttext/po_entry.rb', line 63 def references? !@references.empty? end |
#to_s ⇒ String
Convert the entry to a string representation, to be written to a .po file
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puttext/po_entry.rb', line 46 def to_s str = String.new('') # Add comments str = add_comment(str, ':', @references.join(' ')) if references? # Add id and context str = add_string(str, 'msgctxt', @msgctxt) if @msgctxt str = add_string(str, 'msgid', @msgid) str = add_string(str, 'msgid_plural', @msgid_plural) if plural? str = add_translations(str) str end |
#unique_key ⇒ Object
Return an object uniquely identifying this entry. The returned object can be used to find duplicate entries.
76 77 78 |
# File 'lib/puttext/po_entry.rb', line 76 def unique_key [@msgid, @msgctxt] end |