Class: PoParser::Entry
- Inherits:
-
Object
- Object
- PoParser::Entry
- Defined in:
- lib/poparser/entry.rb
Overview
A single translation entity in a PO file
Instance Method Summary collapse
-
#flag_as(flag) ⇒ Object
Set flag to a custom string.
-
#flag_as_fuzzy ⇒ Entry
Flag the entry as Fuzzy.
-
#fuzzy? ⇒ Boolean
Checks if the entry is fuzzy.
-
#initialize(args = {}) ⇒ Entry
constructor
rubocop:disable Metrics/ClassLength.
- #inspect ⇒ Object
-
#obsolete? ⇒ Boolean
(also: #cached?)
If entry doesn't have any msgid, it's probably a obsolete entry that is kept by the program for later use.
-
#plural? ⇒ Boolean
Checks if the entry is plural.
-
#to_h ⇒ Hash
Convert entry to a hash key value.
-
#to_s ⇒ String
Convert entry to a string.
-
#translated? ⇒ Boolean
(also: #complete?)
Checks if the entry is translated.
-
#untranslated? ⇒ Boolean
(also: #incomplete?)
Checks if the entry is untraslated.
Constructor Details
#initialize(args = {}) ⇒ Entry
rubocop:disable Metrics/ClassLength
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/poparser/entry.rb', line 6 def initialize(args = {}) # Defining all instance variables to prevent warnings define_labels_instance_variables define_args_instance_variables(args) define_writer_methods(COMMENTS_LABELS, 'Comment') define_writer_methods(ENTRIES_LABELS, 'Message') define_reader_methods define_aliases define_obsolete_instance_variables end |
Instance Method Details
#flag_as(flag) ⇒ Object
Set flag to a custom string
73 74 75 76 77 |
# File 'lib/poparser/entry.rb', line 73 def flag_as(flag) raise ArgumentError if flag.class != String @flag = flag end |
#flag_as_fuzzy ⇒ Entry
Flag the entry as Fuzzy
67 68 69 70 |
# File 'lib/poparser/entry.rb', line 67 def flag_as_fuzzy @flag = 'fuzzy' self end |
#fuzzy? ⇒ Boolean
Checks if the entry is fuzzy
58 59 60 61 62 |
# File 'lib/poparser/entry.rb', line 58 def fuzzy? return false if obsolete? @flag.to_s.match?('fuzzy') ? true : false end |
#inspect ⇒ Object
111 112 113 |
# File 'lib/poparser/entry.rb', line 111 def inspect to_s end |
#obsolete? ⇒ Boolean Also known as: cached?
If entry doesn't have any msgid, it's probably a obsolete entry that is kept by the program for later use. These entries will usually start with: #~
22 23 24 |
# File 'lib/poparser/entry.rb', line 22 def obsolete? !@obsolete.nil? end |
#plural? ⇒ Boolean
Checks if the entry is plural
51 52 53 |
# File 'lib/poparser/entry.rb', line 51 def plural? @msgid_plural != nil end |
#to_h ⇒ Hash
Convert entry to a hash key value
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/poparser/entry.rb', line 82 def to_h instance_variables.each_with_object({}) do |label, hash| object = instance_variable_get(label) # If it's a plural msgstr if object.is_a?(Array) object.each do |entry| hash[entry.type] = entry.to_s unless entry.nil? end else hash[object.type] = object.to_s unless object.nil? end end end |
#to_s ⇒ String
Convert entry to a string
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/poparser/entry.rb', line 99 def to_s LABELS.each_with_object([]) do |label, arr| object = instance_variable_get("@#{label}".to_sym) # If it's a plural msgstr if object.is_a?(Array) arr.push(*object.map { |entry| entry.to_s(true) }.compact) else arr << object.to_s(true) unless object.nil? end end.join end |
#translated? ⇒ Boolean Also known as: complete?
Checks if the entry is translated
41 42 43 44 45 |
# File 'lib/poparser/entry.rb', line 41 def translated? return false if obsolete? || fuzzy? !untranslated? end |
#untranslated? ⇒ Boolean Also known as: incomplete?
Checks if the entry is untraslated
30 31 32 33 34 35 |
# File 'lib/poparser/entry.rb', line 30 def untranslated? return false if obsolete? || fuzzy? return @msgstr.map(&:str).join.empty? if @msgstr.is_a? Array @msgstr.nil? || @msgstr.str.empty? end |