|
| 1 | +#-- |
| 2 | +# Copyright (C) 2026 gemmaro |
| 3 | +# |
| 4 | +# This program is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 3 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +#++ |
| 17 | + |
| 18 | +# The main entrypoints to parse PO files are GettextPO::File.new and |
| 19 | +# GettextPO::File.read. |
| 20 | +# |
| 21 | +# == Error handling |
| 22 | +# |
| 23 | +# There are two kinds of errors in this gem. The first is for |
| 24 | +# exception handlings of libgettextpo. The second is regular error |
| 25 | +# raising from this gem. |
| 26 | +# |
| 27 | +# Some functions takes exception error handling paramters like |
| 28 | +# +xerror+ and +xerror2+. These parameters expect +Proc+ object which |
| 29 | +# takes several parameters. See also the description of |
| 30 | +# GettextPO::File.read method. The +severity+ parameter among these |
| 31 | +# parameters is either SEVERITY_WARNING, SEVERITY_ERROR, or |
| 32 | +# SEVERITY_FATAL_ERROR. |
| 33 | +# |
| 34 | +# This gem normally raises +GettextPO::Error+ object, except for the |
| 35 | +# standard ones, +StopIteration+ for example. |
| 36 | +# |
| 37 | +module GettextPO |
| 38 | + Error = Class.new(StandardError) # :nodoc: |
| 39 | + |
| 40 | + # This class doesn't provide the +new+ class method. See also |
| 41 | + # GettextPO::File#message_iterator. |
| 42 | + class MessageIterator |
| 43 | + def self.new |
| 44 | + raise NoMethodError, |
| 45 | + "please use other methods instead, such as GettextPO::File#message_iterator" |
| 46 | + end |
| 47 | + |
| 48 | + def each # yields: message |
| 49 | + while true |
| 50 | + begin |
| 51 | + yield self.next |
| 52 | + rescue StopIteration |
| 53 | + return self |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + include Enumerable |
| 59 | + end |
| 60 | + |
| 61 | + # This class doesn't provide the +new+ class method. Refre to |
| 62 | + # GettextPO::MessageIterator#next or |
| 63 | + # GettextPO::MessageIterator#insert. |
| 64 | + class Message |
| 65 | + def self.new |
| 66 | + raise NoMethodError, |
| 67 | + "please use other methods instead, such as GettextPO::MessageIterator#next" |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + # This class doesn't provide the +new+ class method. See also |
| 72 | + # GettextPO::Message#filepos. |
| 73 | + class FilePos |
| 74 | + def self.new |
| 75 | + raise NoMethodError, |
| 76 | + "please use other methods instead, such as GettextPO::Message#filepos" |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments