[Groonga-commit] groonga/groonga-query-log at 7ec6416 [master] Stop to use English

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Nov 21 18:44:30 JST 2017


Kouhei Sutou	2017-11-21 18:44:30 +0900 (Tue, 21 Nov 2017)

  New Revision: 7ec6416d955aa85ee67a8bd56bcaa94f072ca1e8
  https://github.com/groonga/groonga-query-log/commit/7ec6416d955aa85ee67a8bd56bcaa94f072ca1e8

  Message:
    Stop to use English

  Modified files:
    lib/groonga-query-log/parser.rb

  Modified: lib/groonga-query-log/parser.rb (+28 -13)
===================================================================
--- lib/groonga-query-log/parser.rb    2017-11-21 15:47:27 +0900 (c8dd10f)
+++ lib/groonga-query-log/parser.rb    2017-11-21 18:44:30 +0900 (fcb80a4)
@@ -14,8 +14,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "English"
-
 require "groonga-query-log/statistic"
 
 module GroongaQueryLog
@@ -29,6 +27,12 @@ module GroongaQueryLog
         @parsing_statistics = {}
       end
 
+      PATTERN =
+        /\A(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)
+           \ (?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)\.(?<microsecond>\d+)
+           \|(?<context_id>.+?)
+           \|(?<type>[>:<])/x
+
       # Parses query-log file as stream to
       # {GroongaQueryLog::Analyzer::Statistic}s including some
       # informations for each query.
@@ -41,17 +45,28 @@ module GroongaQueryLog
       def parse(input, &block)
         input.each_line do |line|
           next unless line.valid_encoding?
-          case line
-          when /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+)\|(.+?)\|([>:<])/
-            year, month, day, hour, minutes, seconds, micro_seconds =
-              $1, $2, $3, $4, $5, $6, $7
-            context_id = $8
-            type = $9
-            rest = $POSTMATCH.strip
-            time_stamp = Time.local(year, month, day, hour, minutes, seconds,
-                                    micro_seconds)
-            parse_line(time_stamp, context_id, type, rest, &block)
-          end
+
+          match_data = PATTERN.match(line)
+          next if match_data.nil?
+
+          year = match_data[:year].to_i
+          month = match_data[:month].to_i
+          day = match_data[:day].to_i
+          hour = match_data[:hour].to_i
+          minute = match_data[:minute].to_i
+          second = match_data[:second].to_i
+          microsecond = match_data[:microsecond].to_i
+          context_id = match_data[:context_id]
+          type = match_data[:type]
+          rest = match_data.post_match.strip
+          time_stamp = Time.local(year,
+                                  month,
+                                  day,
+                                  hour,
+                                  minute,
+                                  second,
+                                  microsecond)
+          parse_line(time_stamp, context_id, type, rest, &block)
         end
       end
 
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171121/4959c5c9/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index