charwidth 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59070483ff719b4075da7931e7480b8e3bce0462071f401989b2cd2caac62910
4
- data.tar.gz: afacda6a8e0aa4f002636d1762b556bbc44f1f6ea9fa7aa117fec06b2587de3b
3
+ metadata.gz: 4a160471d7981b5ac57ce572d4f1bd4e718c30d01572865089ca8ae594fb512b
4
+ data.tar.gz: c85aae5292b8aff58894f9af501dfd3c3bc4ee6d2848f6df44e3882399b4c473
5
5
  SHA512:
6
- metadata.gz: 3c4b90161ae75e9fcbdcb7080b8ba3fecad9c2e5bc6d2ae5555f7a8b2bdd6d369c6a075475eed98580439dd0ef0ee039bbeb93bad143905d9af1c60e02017c7f
7
- data.tar.gz: 3b9a483138307b00100e74e59704e375558f106f3ae6b5f575eed3038ca21dd82073d73ef2056647bfce0b8da430d4d69d3dc528ff2d3242268f4996f601bcdc
6
+ metadata.gz: d6ee373af2b62eadff932a240cd06e12493a1e3b7681bcbf4053a75cc9d351f27f59751c1c7c705615659b67554f278245a41fc1a0255dcfe8df672dd5d376c0
7
+ data.tar.gz: 694fde3a7d2b19c772de341a3a6a478cc4befde8fc1ba7c2da0109c994fd58c3bce410abbd473396e6de8f6e8ec5043aa60f34ab88682f7319e48261efa63301
data/.rubocop.yml ADDED
@@ -0,0 +1,127 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/*
4
+ - node_modules/**/*
5
+ NewCops: enable
6
+
7
+ Layout/CaseIndentation:
8
+ EnforcedStyle: end
9
+
10
+ Layout/EndAlignment:
11
+ EnforcedStyleAlignWith: variable
12
+
13
+ Layout/LineLength:
14
+ Enabled: false
15
+
16
+ Layout/EmptyLinesAroundAccessModifier:
17
+ EnforcedStyle: only_before
18
+
19
+ Layout/SpaceInLambdaLiteral:
20
+ EnforcedStyle: require_space
21
+
22
+ Layout/SpaceInsideBlockBraces:
23
+ SpaceBeforeBlockParameters: false
24
+
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: no_space
27
+
28
+ Metrics/AbcSize:
29
+ Enabled: false
30
+
31
+ Metrics/BlockLength:
32
+ Enabled: false
33
+
34
+ Metrics/ClassLength:
35
+ Enabled: false
36
+
37
+ Metrics/CyclomaticComplexity:
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ Enabled: false
42
+
43
+ Metrics/ModuleLength:
44
+ Enabled: false
45
+
46
+ Metrics/PerceivedComplexity:
47
+ Enabled: false
48
+
49
+ Naming/HeredocDelimiterNaming:
50
+ Enabled: false
51
+
52
+ Naming/MethodParameterName:
53
+ Enabled: false
54
+
55
+ Naming/PredicateName:
56
+ Enabled: false
57
+
58
+ Style/Alias:
59
+ EnforcedStyle: prefer_alias_method
60
+
61
+ Style/AsciiComments:
62
+ Enabled: false
63
+
64
+ Style/BlockDelimiters:
65
+ Enabled: false
66
+
67
+ Style/Documentation:
68
+ Enabled: false
69
+
70
+ Style/EmptyCaseCondition:
71
+ Enabled: false
72
+
73
+ Style/EmptyMethod:
74
+ EnforcedStyle: expanded
75
+
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: false
78
+
79
+ Style/HashSyntax:
80
+ Exclude:
81
+ - Rakefile
82
+ - "**/*.rake"
83
+
84
+ Style/Lambda:
85
+ EnforcedStyle: literal
86
+
87
+ Style/IfUnlessModifier:
88
+ Enabled: false
89
+
90
+ Style/MultilineBlockChain:
91
+ Enabled: false
92
+
93
+ Style/NumericLiterals:
94
+ Enabled: false
95
+
96
+ Style/NumericPredicate:
97
+ Enabled: false
98
+
99
+ Style/PercentLiteralDelimiters:
100
+ PreferredDelimiters:
101
+ '%i': '()'
102
+ '%w': '()'
103
+ '%r': '()'
104
+
105
+ Style/SpecialGlobalVars:
106
+ Enabled: false
107
+
108
+ Style/StringLiterals:
109
+ EnforcedStyle: double_quotes
110
+
111
+ Style/StringLiteralsInInterpolation:
112
+ EnforcedStyle: double_quotes
113
+
114
+ Style/SymbolArray:
115
+ Enabled: false
116
+
117
+ Style/TrailingCommaInArguments:
118
+ EnforcedStyleForMultiline: consistent_comma
119
+
120
+ Style/TrailingCommaInArrayLiteral:
121
+ EnforcedStyleForMultiline: consistent_comma
122
+
123
+ Style/TrailingCommaInHashLiteral:
124
+ EnforcedStyleForMultiline: consistent_comma
125
+
126
+ Style/ZeroLengthPredicate:
127
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in charwidth_template.gemspec
4
4
  gemspec
5
+
6
+ gem "activemodel", ">= 3"
7
+ gem "bundler"
8
+ gem "byebug"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rspec-its"
12
+ gem "rubocop"
data/README.md CHANGED
@@ -31,13 +31,19 @@ Or extend String class.
31
31
  "Hello, World!".normalize_charwidth! # => destructive
32
32
  "「ハローワールド」".normalize_charwidth # => "「ハローワールド」"
33
33
 
34
- # ActiveRecord integration
34
+ # Rails integration
35
35
 
36
- Write `require "charwidth/active_record"` to normalize all values of ActiveRecord attributes.
36
+ Add lines below to `app/models/application_record.rb`.
37
37
 
38
- require "charwidth/active_record"
38
+ require "charwidth/active_model"
39
+ class ApplicationRecord < ActiveRecord::Base
40
+ include Charwidth::ActiveModel
41
+ end
42
+
43
+ And call `normalize_charwidth` class method in model class.
39
44
 
40
45
  class Article < ActiveRecord::Base
46
+ normalize_charwidth :title, :body
41
47
  end
42
48
 
43
49
  a = Article.new(title: "Hello, World!")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/charwidth.gemspec CHANGED
@@ -1,28 +1,21 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'charwidth/version'
3
+ require "charwidth/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "charwidth"
8
7
  spec.version = Charwidth::VERSION
9
8
  spec.authors = ["labocho"]
10
9
  spec.email = ["labocho@penguinlab.jp"]
11
- spec.description = %q{Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters}
12
- spec.summary = %q{Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters}
10
+ spec.description = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
11
+ spec.summary = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
13
12
  spec.homepage = "https://github.com/labocho/charwidth"
14
13
  spec.license = "MIT"
15
14
 
16
15
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.executables = spec.files.grep(%r(^bin/)) {|f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "rspec-its"
25
- spec.add_development_dependency "simplecov"
26
- spec.add_development_dependency "activerecord", ">= 3"
27
- spec.add_development_dependency "sqlite3", "< 1.4"
20
+ spec.required_ruby_version = ">= 2.4.0"
28
21
  end
data/lib/charwidth.rb CHANGED
@@ -39,7 +39,7 @@ module Charwidth
39
39
  Characters::SPACE,
40
40
  Characters::IDEOGRAPHIC_SPACE,
41
41
  ],
42
- }
42
+ }.transform_values(&:freeze).freeze
43
43
 
44
44
  # Normalize Unicode fullwidth / halfwidth (zenkaku / hankaku) characters
45
45
  # options: {
@@ -63,7 +63,8 @@ module Charwidth
63
63
  def to_full_width!(src)
64
64
  unify_voiced_katakana!(src)
65
65
 
66
- before, after = "", ""
66
+ before = ""
67
+ after = ""
67
68
  HALFWIDTH_TO_FULLWIDTH.each_value do |half, full|
68
69
  before << half
69
70
  after << full
@@ -77,7 +78,7 @@ module Charwidth
77
78
  private
78
79
  TYPES = [
79
80
  :ascii, :white_parenthesis, :cjk_punctuation, :katakana, :hangul,
80
- :latin_1_punctuation_and_symbols, :mathematical_symbols, :space
81
+ :latin_1_punctuation_and_symbols, :mathematical_symbols, :space,
81
82
  ].freeze
82
83
  def normalize_charwidth!(src, options = {})
83
84
  types = TYPES.dup
@@ -91,28 +92,31 @@ module Charwidth
91
92
  unless (unexpected_types = options[:only] - TYPES).empty?
92
93
  raise "Unexpected normalize type(s): #{unexpected_types.inspect}"
93
94
  end
94
- types = types & options[:only]
95
+
96
+ types &= options[:only]
95
97
  end
96
98
 
97
99
  if options[:expect]
98
100
  unless (unexpected_types = options[:expected] - TYPES).empty?
99
- raise "Unexpected normalize type(s): #{t.inspect}"
101
+ raise "Unexpected normalize type(s): #{unexpected_types.inspect}"
100
102
  end
101
- types = types - options[:expect]
103
+
104
+ types -= options[:expect]
102
105
  end
103
106
 
104
- before, after = "", ""
107
+ before = ""
108
+ after = ""
105
109
  types.each do |type|
106
110
  case type
107
111
  when :ascii, :white_parenthesis, :latin_1_punctuation_and_symbols, :space
108
112
  # convert fullwidth to halfwidth
109
- HALFWIDTH_TO_FULLWIDTH[type].tap{|half, full|
113
+ HALFWIDTH_TO_FULLWIDTH[type].tap {|half, full|
110
114
  before << full
111
115
  after << half
112
116
  }
113
117
  when :cjk_punctuation, :katakana, :hangul, :mathematical_symbols
114
118
  # convert halfwidth to fullwidth
115
- HALFWIDTH_TO_FULLWIDTH[type].tap{|half, full|
119
+ HALFWIDTH_TO_FULLWIDTH[type].tap {|half, full|
116
120
  before << half
117
121
  after << full
118
122
  }
@@ -139,10 +143,10 @@ module Charwidth
139
143
 
140
144
  def escape_for_tr!(s)
141
145
  s.gsub!('\\', '\\\\')
142
- s.gsub!('-', '\\-')
143
- s.gsub!('^', '\\^')
144
- s.gsub!('[', '\\[')
145
- s.gsub!(']', '\\]')
146
+ s.gsub!("-", '\\-')
147
+ s.gsub!("^", '\\^')
148
+ s.gsub!("[", '\\[')
149
+ s.gsub!("]", '\\]')
146
150
  s
147
151
  end
148
152
  end
@@ -0,0 +1,24 @@
1
+ require "charwidth"
2
+
3
+ module Charwidth
4
+ module ActiveModel
5
+ module ClassMethods
6
+ def normalize_charwidth(*attribute_names)
7
+ m = Module.new do
8
+ attribute_names.each do |attribute|
9
+ define_method "#{attribute}=" do |v|
10
+ super(v.nil? ? nil : Charwidth.normalize(v.to_s))
11
+ end
12
+ end
13
+ end
14
+ prepend m
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.class_eval do
20
+ extend ClassMethods
21
+ end
22
+ end
23
+ end
24
+ end
@@ -10,7 +10,7 @@ module Charwidth
10
10
  (0xffc2..0xffc7).to_a,
11
11
  (0xffca..0xffcf).to_a,
12
12
  (0xffd2..0xffd7).to_a,
13
- (0xffda..0xffdc).to_a
13
+ (0xffda..0xffdc).to_a,
14
14
  ].flatten.pack("U*").freeze
15
15
  FULLWIDTH_SYMBOL_VARIANTS = (0xffe0..0xffe6).to_a.pack("U*").freeze
16
16
  HALFWIDTH_SYMBOL_VARIANTS = (0xffe8..0xffee).to_a.pack("U*").freeze
@@ -39,7 +39,7 @@ module Charwidth
39
39
  ].flatten.pack("U*").freeze
40
40
  HANGUL = [
41
41
  0x3164, # HANGUL FILLER
42
- (0x3131..0x3163).to_a # HANGUL LETTER KIYEOK to I
42
+ (0x3131..0x3163).to_a, # HANGUL LETTER KIYEOK to I
43
43
  ].flatten.pack("U*").freeze
44
44
  LATIN_1_PUNCTUATION_AND_SYMBOLS = [
45
45
  0x00a2, # CENT SIGN
@@ -48,33 +48,33 @@ module Charwidth
48
48
  0x00af, # MACRON
49
49
  0x00a6, # BROKEN BAR
50
50
  0x00a5, # YEN SIGN
51
- 0x20a9 # WON SIGN
51
+ 0x20a9, # WON SIGN
52
52
  ].pack("U*").freeze
53
53
  MATHEMATICAL_SYMBOLS = [
54
54
  0x2502, # BOX DRAWINGS LIGHT VERTICAL
55
55
  (0x2190..0x2193).to_a, # LEFTWARDS, UPWARDS, RIGHTWARDS, DOWNWARDS ARROW
56
56
  0x25a0, # BLACK SQUARE
57
- 0x25cb # WHITE CIRCLE
57
+ 0x25cb, # WHITE CIRCLE
58
58
  ].flatten.pack("U*").freeze
59
59
  SPACE = "\u0020".freeze
60
60
 
61
- HALFWIDTH_KATAKANA_VOICED_SOUND_MARK = "\uff9e"
61
+ HALFWIDTH_KATAKANA_VOICED_SOUND_MARK = "\uff9e".freeze
62
62
  HALFWIDTH_VOICED_KATAKANA = [
63
63
  (0xff76..0xff84).to_a, # HALFWIDTH KATAKANA LETTER KA to TO
64
64
  (0xff8a..0xff8e).to_a, # HALFWIDTH KATAKANA LETTER HA to HO
65
- 0xff73 # HALFWIDTH KATAKANA LETTER U
66
- ].flatten.map{|k| ([k].pack("U") + HALFWIDTH_KATAKANA_VOICED_SOUND_MARK).freeze }.freeze
65
+ 0xff73, # HALFWIDTH KATAKANA LETTER U
66
+ ].flatten.map {|k| ([k].pack("U") + HALFWIDTH_KATAKANA_VOICED_SOUND_MARK).freeze }.freeze
67
67
  VOICED_KATAKANA = [
68
68
  0x30ac.step(0x30be, 2).to_a, # KATAKANA LETTER GA to ZO
69
69
  [0x30c0, 0x30c2, 0x30c5, 0x30c7, 0x30c9], # KATAKANA LETTER DA to DO
70
70
  0x30d0.step(0x30dc, 3).to_a, # KATAKANA LETTER BA to BO
71
- 0x30f4 # KATAKANA LETTER VU
72
- ].flatten.map{|c| [c].pack("U").freeze }.freeze
71
+ 0x30f4, # KATAKANA LETTER VU
72
+ ].flatten.map {|c| [c].pack("U").freeze }.freeze
73
73
 
74
- HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK = "\uff9f"
74
+ HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK = "\uff9f".freeze
75
75
  HALFWIDTH_SEMI_VOICED_KATAKANA = [
76
- (0xff8a..0xff8e).to_a # HALFWIDTH KATAKANA LETTER HA to HO
77
- ].flatten.map{|k| ([k].pack("U") + HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK).freeze }.freeze
78
- SEMI_VOICED_KATAKANA = 0x30d1.step(0x30dd, 3).map{|c| [c].pack("U").freeze }.flatten.freeze # KATAKANA LETTER PA to PO
76
+ (0xff8a..0xff8e).to_a, # HALFWIDTH KATAKANA LETTER HA to HO
77
+ ].flatten.map {|k| ([k].pack("U") + HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK).freeze }.freeze
78
+ SEMI_VOICED_KATAKANA = 0x30d1.step(0x30dd, 3).map {|c| [c].pack("U").freeze }.flatten.freeze # KATAKANA LETTER PA to PO
79
79
  end
80
80
  end
data/lib/charwidth/cli.rb CHANGED
@@ -9,18 +9,18 @@ module Charwidth
9
9
  options = {}
10
10
  optparse = OptionParser.new do |o|
11
11
  o.banner += " TEXT\nNormalize character width in arguments or STDIN.\nAvailable character types are #{Charwidth::ClassMethods::TYPES.join(",")}."
12
- o.on("--only=TYPES", "Comma separated character types that should be converted"){|types| options[:only] = types.split(",").map(&:to_sym) }
13
- o.on("--except=TYPES", "Comma separated character types that should not be converted"){|types| options[:except] = types.split(",").map(&:to_sym) }
12
+ o.on("--only=TYPES", "Comma separated character types that should be converted") {|types| options[:only] = types.split(",").map(&:to_sym) }
13
+ o.on("--except=TYPES", "Comma separated character types that should not be converted") {|types| options[:except] = types.split(",").map(&:to_sym) }
14
14
  o.parse!(argv)
15
15
  end
16
16
  src = nil
17
17
  if ARGV.empty?
18
- if STDIN.tty?
19
- STDERR.puts optparse.banner
20
- STDERR.puts optparse.help
18
+ if $stdin.tty?
19
+ warn optparse.banner
20
+ warn optparse.help
21
21
  exit 1
22
22
  else
23
- src = STDIN.read
23
+ src = $stdin.read
24
24
  end
25
25
  else
26
26
  src = ARGV.join(" ")
@@ -1,3 +1,3 @@
1
1
  module Charwidth
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "active_model"
3
+ require "charwidth/active_model"
4
+
5
+ describe Charwidth::ActiveModel do
6
+ before(:all) do
7
+ # rubocop:disable Lint/ConstantDefinitionInBlock
8
+ class User
9
+ include ActiveModel::Attributes
10
+ include Charwidth::ActiveModel
11
+
12
+ attribute :name, :string
13
+ normalize_charwidth :name
14
+
15
+ def initialize(name: nil)
16
+ super()
17
+ self.name = name
18
+ end
19
+ end
20
+ # rubocop:enable Lint/ConstantDefinitionInBlock
21
+ end
22
+
23
+ after(:all) do
24
+ Object.send(:remove_const, :User)
25
+ end
26
+
27
+ subject { User.new }
28
+ context "assign unnormalized valud" do
29
+ before(:each) do
30
+ subject.name = "ABCアイウ"
31
+ end
32
+ its(:name) { should == "ABCアイウ" }
33
+ end
34
+ context "assign nil" do
35
+ before(:each) do
36
+ subject.name = nil
37
+ end
38
+ its(:name) { should.nil? }
39
+ end
40
+ context "mass assignment" do
41
+ subject { User.new(name: "ABCアイウ") }
42
+ its(:name) { should == "ABCアイウ" }
43
+ end
44
+ end
@@ -1,5 +1,4 @@
1
- # encoding: UTF-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
3
2
 
4
3
  describe "Charwidth" do
5
4
  describe ".normalize" do
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,14 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'rspec/its'
5
- require 'charwidth'
3
+ require "rspec"
4
+ require "rspec/its"
5
+ require "charwidth"
6
+ require "byebug"
6
7
 
7
8
  # Requires supporting files with custom matchers and macros, etc,
8
9
  # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ Dir["#{__dir__}/support/**/*.rb"].sort.each {|f| require f }
10
11
 
11
12
  RSpec.configure do |config|
12
-
13
+ # noop
13
14
  end
metadata CHANGED
@@ -1,119 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charwidth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - labocho
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec-its
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: activerecord
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '3'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '3'
97
- - !ruby/object:Gem::Dependency
98
- name: sqlite3
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "<"
102
- - !ruby/object:Gem::Version
103
- version: '1.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "<"
109
- - !ruby/object:Gem::Version
110
- version: '1.4'
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
+ dependencies: []
111
13
  description: Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku)
112
14
  characters
113
15
  email:
114
16
  - labocho@penguinlab.jp
115
17
  executables:
116
18
  - charwidth
19
+ - rspec
20
+ - rubocop
117
21
  extensions: []
118
22
  extra_rdoc_files: []
119
23
  files:
@@ -121,6 +25,7 @@ files:
121
25
  - ".document"
122
26
  - ".gitignore"
123
27
  - ".rspec"
28
+ - ".rubocop.yml"
124
29
  - CHANGELOG.md
125
30
  - Gemfile
126
31
  - Gemfile.lock
@@ -128,21 +33,23 @@ files:
128
33
  - README.md
129
34
  - Rakefile
130
35
  - bin/charwidth
36
+ - bin/rspec
37
+ - bin/rubocop
131
38
  - charwidth.gemspec
132
39
  - lib/charwidth.rb
133
- - lib/charwidth/active_record.rb
40
+ - lib/charwidth/active_model.rb
134
41
  - lib/charwidth/characters.rb
135
42
  - lib/charwidth/cli.rb
136
43
  - lib/charwidth/string.rb
137
44
  - lib/charwidth/version.rb
138
- - spec/charwidth/active_record_spec.rb
45
+ - spec/charwidth/active_model_spec.rb
139
46
  - spec/charwidth_spec.rb
140
47
  - spec/spec_helper.rb
141
48
  homepage: https://github.com/labocho/charwidth
142
49
  licenses:
143
50
  - MIT
144
51
  metadata: {}
145
- post_install_message:
52
+ post_install_message:
146
53
  rdoc_options: []
147
54
  require_paths:
148
55
  - lib
@@ -150,19 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
57
  requirements:
151
58
  - - ">="
152
59
  - !ruby/object:Gem::Version
153
- version: '0'
60
+ version: 2.4.0
154
61
  required_rubygems_version: !ruby/object:Gem::Requirement
155
62
  requirements:
156
63
  - - ">="
157
64
  - !ruby/object:Gem::Version
158
65
  version: '0'
159
66
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.7.6
162
- signing_key:
67
+ rubygems_version: 3.1.2
68
+ signing_key:
163
69
  specification_version: 4
164
70
  summary: Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters
165
71
  test_files:
166
- - spec/charwidth/active_record_spec.rb
72
+ - spec/charwidth/active_model_spec.rb
167
73
  - spec/charwidth_spec.rb
168
74
  - spec/spec_helper.rb
@@ -1,27 +0,0 @@
1
- require "charwidth"
2
-
3
- module Charwidth
4
- module ActiveRecord
5
- module InstanceMethods
6
- def write_attribute_with_normalize_charwidth(attr_name, value)
7
- value = value.is_a?(String) ? Charwidth.normalize(value) : value
8
- write_attribute_without_normalize_charwidth(attr_name, value)
9
- end
10
- end
11
-
12
- def self.included(base)
13
- base.class_eval do
14
- include InstanceMethods
15
- if ::ActiveRecord.version<Gem::Version.new("5.2")
16
- alias_method :write_attribute_without_normalize_charwidth, :write_attribute
17
- alias_method :write_attribute, :write_attribute_with_normalize_charwidth
18
- else
19
- alias_method :write_attribute_without_normalize_charwidth, :_write_attribute
20
- alias_method :_write_attribute, :write_attribute_with_normalize_charwidth
21
- end
22
- end
23
- end
24
- end
25
- end
26
-
27
- ActiveRecord::Base.send(:include, Charwidth::ActiveRecord)
@@ -1,39 +0,0 @@
1
- # encoding: UTF-8
2
- require "spec_helper"
3
- require "active_record"
4
- require "charwidth/active_record"
5
-
6
- describe Charwidth::ActiveRecord do
7
- before(:all) do
8
- ActiveRecord::Base.establish_connection(
9
- adapter: "sqlite3",
10
- database: ":memory:"
11
- )
12
- ActiveRecord::Base.connection.execute <<-SQL
13
- CREATE TABLE users (
14
- id integer PRIMARY KEY AUTOINCREMENT,
15
- name text NOT NULL
16
- )
17
- SQL
18
-
19
- class User < ActiveRecord::Base; end
20
- end
21
-
22
- subject { User.new }
23
- context 'assign unnormalized valud' do
24
- before(:each) do
25
- subject.name = "ABCアイウ"
26
- end
27
- its(:name) { should == "ABCアイウ" }
28
- end
29
- context 'assign nil' do
30
- before(:each) do
31
- subject.name = nil
32
- end
33
- its(:name) { should == nil }
34
- end
35
- context 'mass assignment' do
36
- subject { User.new(name: "ABCアイウ") }
37
- its(:name) { should == "ABCアイウ" }
38
- end
39
- end