Skip to content

Commit 1a077f1

Browse files
committed
Commonize Ruby code.
1 parent 736d1a2 commit 1a077f1

4 files changed

Lines changed: 80 additions & 85 deletions

File tree

lib/gettextpo.rb

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,4 @@
1717

1818
require_relative "gettextpo/version"
1919
require_relative "gettextpo/gettextpo"
20-
21-
# The main entrypoints to parse PO files are GettextPO::File.new and
22-
# GettextPO::File.read.
23-
#
24-
# == Error handling
25-
#
26-
# There are two kinds of errors in this gem. The first is for
27-
# exception handlings of libgettextpo. The second is regular error
28-
# raising from this gem.
29-
#
30-
# Some functions takes exception error handling paramters like
31-
# +xerror+ and +xerror2+. These parameters expect +Proc+ object which
32-
# takes several parameters. See also the description of
33-
# GettextPO::File.read method. The +severity+ parameter among these
34-
# parameters is either SEVERITY_WARNING, SEVERITY_ERROR, or
35-
# SEVERITY_FATAL_ERROR.
36-
#
37-
# This gem normally raises +GettextPO::Error+ object, except for the
38-
# standard ones, +StopIteration+ for example.
39-
#
40-
module GettextPO
41-
class Error < StandardError; end # :nodoc:
42-
43-
# This class doesn't provide the +new+ class method. Refre to
44-
# GettextPO::MessageIterator#next or
45-
# GettextPO::MessageIterator#insert.
46-
class Message
47-
private_class_method :new
48-
end
49-
50-
# This class doesn't provide the +new+ class method. See also
51-
# GettextPO::File#message_iterator.
52-
class MessageIterator
53-
private_class_method :new
54-
55-
def each # yields: message
56-
while true
57-
begin
58-
yield self.next
59-
rescue StopIteration
60-
return self
61-
end
62-
end
63-
end
64-
65-
include Enumerable
66-
end
67-
68-
# This class doesn't provide the +new+ class method. See also
69-
# GettextPO::Message#filepos.
70-
class FilePos
71-
private_class_method :new
72-
end
73-
end
20+
require_relative "../mrblib/mrb_gettextpo_common"

mrblib/mrb_gettextpo.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,7 @@ def check_all(xerror: nil, xerror2: nil)
3737
end
3838
end
3939

40-
class MessageIterator
41-
def self.new
42-
raise NoMethodError,
43-
"please use other methods instead, such as GettextPO::File#message_iterator"
44-
end
45-
46-
def each # yields: message
47-
while true
48-
begin
49-
yield self.next
50-
rescue StopIteration
51-
return self
52-
end
53-
end
54-
end
55-
56-
include Enumerable
57-
end
58-
5940
class Message
60-
def self.new
61-
raise NoMethodError,
62-
"please use other methods instead, such as GettextPO::MessageIterator#next"
63-
end
64-
6541
# It seems that calling Proc with keyword arguments is not yet
6642
# supported.
6743
alias original_check_all check_all
@@ -79,11 +55,4 @@ def check_format(xerror: nil, xerror2: nil)
7955
xerror2: xerror2 && Proc.new { |kwargs| xerror2.(**kwargs) })
8056
end
8157
end
82-
83-
class FilePos
84-
def self.new
85-
raise NoMethodError,
86-
"please use other methods instead, such as GettextPO::Message#filepos"
87-
end
88-
end
8958
end

mrblib/mrb_gettextpo_common.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)