Class: PoParser::Header
- Inherits:
-
Object
- Object
- PoParser::Header
- Defined in:
- lib/poparser/header.rb
Overview
The very first entry of the PO file is considered the header
Instance Attribute Summary collapse
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
-
#language ⇒ Object
Returns the value of attribute language.
-
#last_translator ⇒ Object
Returns the value of attribute last_translator.
-
#original_configs ⇒ Object
readonly
Returns the value of attribute original_configs.
-
#plural_forms ⇒ Object
Returns the value of attribute plural_forms.
-
#po_revision_date ⇒ Object
Returns the value of attribute po_revision_date.
-
#pot_creation_date ⇒ Object
Returns the value of attribute pot_creation_date.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#report_to ⇒ Object
Returns the value of attribute report_to.
-
#team ⇒ Object
Returns the value of attribute team.
Instance Method Summary collapse
- #configs ⇒ Object
-
#flag_as(flag) ⇒ Object
Set flag to a custom string.
-
#flag_as_fuzzy ⇒ Header
Flag the entry as Fuzzy.
-
#fuzzy? ⇒ Boolean
Checks if the entry is fuzzy.
-
#initialize(entry) ⇒ Header
constructor
A new instance of Header.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(entry) ⇒ Header
Returns a new instance of Header.
11 12 13 14 15 16 17 18 |
# File 'lib/poparser/header.rb', line 11 def initialize(entry) @entry = entry @comments = entry.translator_comment.value unless entry.translator_comment.nil? @original_configs = convert_msgstr_to_hash(entry.msgstr) @flag = entry.flag define_labels_instance_variables end |
Instance Attribute Details
#charset ⇒ Object
Returns the value of attribute charset.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def charset @charset end |
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def comments @comments end |
#encoding ⇒ Object
Returns the value of attribute encoding.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def encoding @encoding end |
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
6 7 8 |
# File 'lib/poparser/header.rb', line 6 def entry @entry end |
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
6 7 8 |
# File 'lib/poparser/header.rb', line 6 def flag @flag end |
#language ⇒ Object
Returns the value of attribute language.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def language @language end |
#last_translator ⇒ Object
Returns the value of attribute last_translator.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def last_translator @last_translator end |
#original_configs ⇒ Object (readonly)
Returns the value of attribute original_configs.
6 7 8 |
# File 'lib/poparser/header.rb', line 6 def original_configs @original_configs end |
#plural_forms ⇒ Object
Returns the value of attribute plural_forms.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def plural_forms @plural_forms end |
#po_revision_date ⇒ Object
Returns the value of attribute po_revision_date.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def po_revision_date @po_revision_date end |
#pot_creation_date ⇒ Object
Returns the value of attribute pot_creation_date.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def pot_creation_date @pot_creation_date end |
#project_id ⇒ Object
Returns the value of attribute project_id.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def project_id @project_id end |
#report_to ⇒ Object
Returns the value of attribute report_to.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def report_to @report_to end |
#team ⇒ Object
Returns the value of attribute team.
7 8 9 |
# File 'lib/poparser/header.rb', line 7 def team @team end |
Instance Method Details
#configs ⇒ Object
20 21 22 23 24 25 |
# File 'lib/poparser/header.rb', line 20 def configs configs = HEADER_LABELS.each_with_object({}) do |(k, v), hash| hash[v] = instance_variable_get "@#{k}".to_sym end @original_configs.merge(configs) end |
#flag_as(flag) ⇒ Object
Set flag to a custom string
43 44 45 46 47 |
# File 'lib/poparser/header.rb', line 43 def flag_as(flag) raise ArgumentError if flag.class != String @flag = flag end |
#flag_as_fuzzy ⇒ Header
Flag the entry as Fuzzy
37 38 39 40 |
# File 'lib/poparser/header.rb', line 37 def flag_as_fuzzy @flag = 'fuzzy' self end |
#fuzzy? ⇒ Boolean
Checks if the entry is fuzzy
30 31 32 |
# File 'lib/poparser/header.rb', line 30 def fuzzy? @flag.to_s.match?('fuzzy') ? true : false end |
#inspect ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/poparser/header.rb', line 75 def inspect string = [] if @comments.is_a?(Array) @comments.each do |comment| string << "# #{comment}".strip end else string << "# #{@comments}".strip end string << "#, #{@flag}" if @flag string << "msgid \"\"\nmsgstr \"\"" configs.each do |k, v| next if v.nil? || v.empty? string << "#{k}: #{v}\n".dump end string.join("\n") end |
#to_h ⇒ Object
49 50 51 |
# File 'lib/poparser/header.rb', line 49 def to_h @entry.to_h end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/poparser/header.rb', line 53 def to_s string = [] if @comments.is_a?(Array) @comments.each do |comment| string << "# #{comment}".strip end else string << "# #{@comments}".strip end string << "#, #{@flag}" if @flag string << "msgid \"\"\nmsgstr \"\"" configs.each do |k, v| if v.nil? || v.empty? puts "WARNING: \"#{k}\" header field is empty and skipped" next end string << "#{k}: #{v}\n".dump end string.join("\n") end |