Skip to content

Commit 9442df4

Browse files
committed
init
0 parents  commit 9442df4

21 files changed

+445
-0
lines changed

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '3.4.2'
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
bundler-cache: true
26+
- name: Install mecab
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install libmecab-dev mecab-ipadic-utf8
30+
- name: Run the default task
31+
run: bundle exec rake

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/.bundle/
2+
/.vscode/
3+
/.yardoc
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
*.bundle
11+
*.so
12+
*.o
13+
*.a
14+
mkmf.log
15+
Gemfile.lock

.rubocop.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins:
2+
- rubocop-rake
3+
- rubocop-minitest
4+
5+
AllCops:
6+
TargetRubyVersion: 3.1
7+
NewCops: enable
8+
9+
Style/StringLiterals:
10+
EnforcedStyle: double_quotes
11+
12+
Style/StringLiteralsInInterpolation:
13+
EnforcedStyle: double_quotes

Gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in mecab.gemspec
6+
gemspec
7+
8+
gem "rake", "~> 13.0"
9+
10+
gem "rake-compiler"
11+
12+
gem "minitest", "~> 5.16"
13+
14+
gem "rubocop", "~> 1.21"
15+
gem "rubocop-minitest"
16+
gem "rubocop-rake"

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 Xinyu Wang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mecab.rb
2+
3+
Ruby binding for [MeCab](https://github.com/markburns/mecab).
4+
5+
It only supports segmentation feature for now.

Rakefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "minitest/test_task"
5+
6+
Minitest::TestTask.create
7+
8+
require "rubocop/rake_task"
9+
10+
RuboCop::RakeTask.new
11+
12+
require "rake/extensiontask"
13+
14+
desc "Build Ruby Gem"
15+
task build: :compile
16+
17+
GEMSPEC = Gem::Specification.load("mecab.gemspec")
18+
19+
Rake::ExtensionTask.new("mecab", GEMSPEC) do |ext|
20+
ext.lib_dir = "lib/mecab"
21+
end
22+
23+
task default: %i[clobber compile test rubocop]

bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "mecab"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

ext/mecab/extconf.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require "mkmf"
4+
5+
begin
6+
find_executable("mecab-config") or abort "mecab-config not found"
7+
rescue SystemExit
8+
install_text = case RUBY_PLATFORM
9+
when /linux/
10+
"apt install libmecab-dev mecab-ipadic-utf8"
11+
when /darwin/
12+
"brew install mecab mecab-ipadic"
13+
else
14+
"We don't know how to install mecab on your platform"
15+
end
16+
17+
abort <<~MSG
18+
mecab is missing. You can install it by running:
19+
#{install_text}
20+
MSG
21+
end
22+
23+
mecab_config = with_config("mecab-config", "mecab-config")
24+
enable_config("mecab-config")
25+
26+
append_cflags("-fvisibility=hidden -std=c11 -O3 -g")
27+
append_cflags(`#{mecab_config} --cflags`.chomp)
28+
29+
append_cppflags("-fvisibility=hidden -std=c++11 -O3 -g")
30+
append_cppflags(`#{mecab_config} --cflags`.chomp)
31+
32+
append_ldflags(`#{mecab_config} --libs`.chomp)
33+
34+
includes = [RbConfig::CONFIG["includedir"]]
35+
includes += `#{mecab_config} --inc-dir`.chomp.split
36+
libs = [RbConfig::CONFIG["libdir"]]
37+
dir_config("mecab", includes, libs)
38+
39+
create_makefile("mecab/mecab")

0 commit comments

Comments
 (0)