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
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#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.
-
#msgstr ⇒ Object
readonly
Returns the value of attribute msgstr.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#flags? ⇒ Boolean
Check if the entry has any flags.
-
#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
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puttext/po_entry.rb', line 37 def initialize(attrs) id, ctx = extract_context( attrs[:msgid], attrs[:separator] || NS_SEPARATOR ) @msgid = id @msgctxt = attrs[:msgctxt] || ctx @msgid_plural = attrs[:msgid_plural] @msgstr = Array(attrs[:msgstr] || '') @references = attrs[:references] || [] @flags = attrs[:flags] || [] end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
19 20 21 |
# File 'lib/puttext/po_entry.rb', line 19 def flags @flags end |
#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 |
#msgstr ⇒ Object (readonly)
Returns the value of attribute msgstr.
18 19 20 |
# File 'lib/puttext/po_entry.rb', line 18 def msgstr @msgstr end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
20 21 22 |
# File 'lib/puttext/po_entry.rb', line 20 def references @references end |
Instance Method Details
#==(other) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/puttext/po_entry.rb', line 104 def ==(other) @msgid == other.msgid && @msgid_plural == other.msgid_plural && @msgctxt == other.msgctxt && @references == other.references end |
#flags? ⇒ Boolean
Check if the entry has any flags.
76 77 78 |
# File 'lib/puttext/po_entry.rb', line 76 def flags? !@flags.empty? 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.
99 100 101 102 |
# File 'lib/puttext/po_entry.rb', line 99 def merge(other_entry) @references += other_entry.references self end |
#plural? ⇒ Boolean
Check if the entry has a plural form.
82 83 84 |
# File 'lib/puttext/po_entry.rb', line 82 def plural? !@msgid_plural.nil? end |
#references? ⇒ Boolean
Check if the entry has any references.
70 71 72 |
# File 'lib/puttext/po_entry.rb', line 70 def references? !@references.empty? end |
#to_s ⇒ String
Convert the entry to a string representation, to be written to a .po file
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puttext/po_entry.rb', line 52 def to_s str = String.new('') # Add comments str = add_comment(str, ':', @references.join(' ')) if references? str = add_comment(str, ',', @flags.join("\n")) if flags? # 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.
89 90 91 |
# File 'lib/puttext/po_entry.rb', line 89 def unique_key [@msgid, @msgctxt] end |