ruremasearcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +7 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +94 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/bin/ruremasearcher +48 -0
- data/lib/auto_redirector.rb +28 -0
- data/lib/html_parser.rb +19 -0
- data/lib/ruremasearcher/version.rb +3 -0
- data/ruremasearcher.gemspec +24 -0
- data/spec/ruremasearcher/ruremasearcher_spec.rb +132 -0
- data/spec/spec_helper.rb +17 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc27b0f856b25b574b881fd9e8ce673807010e7a
|
4
|
+
data.tar.gz: ab2860421eb3e24c9f86bfedd904017126ef21c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1943172a428a81784ddd049c29df4cc8a43d2e2fd02b01825dd531db7449d1fdf58327d24164ec806b491a3099d47c1d36ed4e72b1e997b8324efd65788402d7
|
7
|
+
data.tar.gz: aa1c1153e6ae21900e29235c423296406a00fdaec5fc6bf4d3acbf1ba6f41c5c3fd563bb52f48a910fb48d06b8f3391caa9c09a05ee1898948f9faf498ec8053
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-10-05 00:50:19 +0900 using RuboCop version 0.26.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Cop supports --auto-correct.
|
10
|
+
Lint/UnusedMethodArgument:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Offense count: 3
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
20
|
+
Style/HashSyntax:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# Offense count: 2
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
# Configuration parameters: PreferredDelimiters.
|
26
|
+
Style/PercentLiteralDelimiters:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Offense count: 2
|
30
|
+
Style/RegexpLiteral:
|
31
|
+
MaxSlashes: 0
|
32
|
+
|
33
|
+
# Offense count: 18
|
34
|
+
# Cop supports --auto-correct.
|
35
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
36
|
+
Style/StringLiterals:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Offense count: 2
|
40
|
+
# Cop supports --auto-correct.
|
41
|
+
Style/UnneededPercentQ:
|
42
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ruremasearcher.gemspec
|
4
|
+
gemspec
|
5
|
+
gem 'rspec', '~> 2.14.1'
|
6
|
+
gem 'simplecov', '~> 0.9.1'
|
7
|
+
gem 'thor', '~> 0.19.1'
|
8
|
+
gem 'rubocop', '~> 0.26.1'
|
9
|
+
gem 'nokogiri'
|
10
|
+
gem 'mechanize', '~> 2.7.3'
|
11
|
+
group :test do
|
12
|
+
gem 'coveralls', :require => false
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruremasearcher (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.0.0)
|
10
|
+
astrolabe (1.3.0)
|
11
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
12
|
+
coveralls (0.7.1)
|
13
|
+
multi_json (~> 1.3)
|
14
|
+
rest-client
|
15
|
+
simplecov (>= 0.7)
|
16
|
+
term-ansicolor
|
17
|
+
thor
|
18
|
+
diff-lcs (1.2.5)
|
19
|
+
docile (1.1.5)
|
20
|
+
domain_name (0.5.21)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
http-cookie (1.0.2)
|
23
|
+
domain_name (~> 0.5)
|
24
|
+
mechanize (2.7.3)
|
25
|
+
domain_name (~> 0.5, >= 0.5.1)
|
26
|
+
http-cookie (~> 1.0)
|
27
|
+
mime-types (~> 2.0)
|
28
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
29
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
30
|
+
nokogiri (~> 1.4)
|
31
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
32
|
+
webrobots (>= 0.0.9, < 0.2)
|
33
|
+
mime-types (2.3)
|
34
|
+
mini_portile (0.6.0)
|
35
|
+
multi_json (1.10.1)
|
36
|
+
net-http-digest_auth (1.4)
|
37
|
+
net-http-persistent (2.9.4)
|
38
|
+
netrc (0.7.7)
|
39
|
+
nokogiri (1.6.3.1)
|
40
|
+
mini_portile (= 0.6.0)
|
41
|
+
ntlm-http (0.1.1)
|
42
|
+
parser (2.2.0.pre.5)
|
43
|
+
ast (>= 1.1, < 3.0)
|
44
|
+
slop (~> 3.4, >= 3.4.5)
|
45
|
+
powerpack (0.0.9)
|
46
|
+
rainbow (2.0.0)
|
47
|
+
rake (10.3.2)
|
48
|
+
rest-client (1.7.2)
|
49
|
+
mime-types (>= 1.16, < 3.0)
|
50
|
+
netrc (~> 0.7)
|
51
|
+
rspec (2.14.1)
|
52
|
+
rspec-core (~> 2.14.0)
|
53
|
+
rspec-expectations (~> 2.14.0)
|
54
|
+
rspec-mocks (~> 2.14.0)
|
55
|
+
rspec-core (2.14.8)
|
56
|
+
rspec-expectations (2.14.5)
|
57
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
58
|
+
rspec-mocks (2.14.6)
|
59
|
+
rubocop (0.26.1)
|
60
|
+
astrolabe (~> 1.3)
|
61
|
+
parser (>= 2.2.0.pre.4, < 3.0)
|
62
|
+
powerpack (~> 0.0.6)
|
63
|
+
rainbow (>= 1.99.1, < 3.0)
|
64
|
+
ruby-progressbar (~> 1.4)
|
65
|
+
ruby-progressbar (1.6.0)
|
66
|
+
simplecov (0.9.1)
|
67
|
+
docile (~> 1.1.0)
|
68
|
+
multi_json (~> 1.0)
|
69
|
+
simplecov-html (~> 0.8.0)
|
70
|
+
simplecov-html (0.8.0)
|
71
|
+
slop (3.6.0)
|
72
|
+
term-ansicolor (1.3.0)
|
73
|
+
tins (~> 1.0)
|
74
|
+
thor (0.19.1)
|
75
|
+
tins (1.3.3)
|
76
|
+
unf (0.1.4)
|
77
|
+
unf_ext
|
78
|
+
unf_ext (0.0.6)
|
79
|
+
webrobots (0.1.1)
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
bundler (~> 1.5)
|
86
|
+
coveralls
|
87
|
+
mechanize (~> 2.7.3)
|
88
|
+
nokogiri
|
89
|
+
rake
|
90
|
+
rspec (~> 2.14.1)
|
91
|
+
rubocop (~> 0.26.1)
|
92
|
+
ruremasearcher!
|
93
|
+
simplecov (~> 0.9.1)
|
94
|
+
thor (~> 0.19.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ryosy383
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ruremasearcher
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ruremasearcher'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ruremasearcher
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/ruremasearcher/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/ruremasearcher
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'auto_redirector'
|
5
|
+
require 'html_parser'
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
module RuremaSearcher
|
9
|
+
class CLI < Thor
|
10
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
|
11
|
+
class_option :version, type: :boolean, desc: 'version'
|
12
|
+
default_task :search
|
13
|
+
|
14
|
+
desc 'search', 'Search in http://rurema.clear-code.com/'
|
15
|
+
def search(words)
|
16
|
+
agent = 'Linux Firefox'
|
17
|
+
url = 'http://rurema.clear-code.com/'
|
18
|
+
ar = AutoRedirector.new(agent)
|
19
|
+
ar.get(url)
|
20
|
+
search_result = ar.search(words)
|
21
|
+
|
22
|
+
hp = HtmlParser.new(search_result.body.toutf8)
|
23
|
+
hp.parse
|
24
|
+
top5 = hp.titles.size - 1 >= 5 ? 5 : hp.titles.size - 1
|
25
|
+
(top5).times do |i|
|
26
|
+
out = <<-EOS
|
27
|
+
---検索結果:#{ i+1 }件目------------------------------
|
28
|
+
タイトル: #{hp.titles[i].text.strip if hp.titles[i]}
|
29
|
+
分類:#{hp.metadata[i].text.strip if hp.metadata[i]}
|
30
|
+
要約:#{hp.summaries[i].text.strip if hp.summaries[i]}
|
31
|
+
説明:#{hp.descriptions[i].text.strip if hp.descriptions[i]}
|
32
|
+
EOS
|
33
|
+
print out
|
34
|
+
end
|
35
|
+
exit(true)
|
36
|
+
rescue => e
|
37
|
+
warn(e.message)
|
38
|
+
exit(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'version', 'version'
|
42
|
+
def version
|
43
|
+
p RuremaSearcher::VERSION
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
RuremaSearcher::CLI.start(ARGV)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'mechanize'
|
4
|
+
|
5
|
+
class AutoRedirector
|
6
|
+
attr_accessor :agent
|
7
|
+
|
8
|
+
def initialize(agent)
|
9
|
+
self.set_agent(agent)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_agent(agent)
|
13
|
+
@agent = Mechanize.new do |a|
|
14
|
+
a.user_agent_alias = agent
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(url)
|
19
|
+
@agent.get(url)
|
20
|
+
end
|
21
|
+
|
22
|
+
def search(words)
|
23
|
+
form = @agent.page.forms[0]
|
24
|
+
form.fields[0].value = words
|
25
|
+
form.submit
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/html_parser.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class HtmlParser
|
6
|
+
attr_accessor :doc, :titles, :metadata, :summaries, :descriptions
|
7
|
+
|
8
|
+
def initialize(html)
|
9
|
+
@doc = Nokogiri::HTML.parse(html)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
@titles = @doc.css('dt > h3')
|
14
|
+
@metadata = @doc.css('ul.entry-metadata > li.entry-type > span')
|
15
|
+
@summaries = @doc.css('div.entry-summary > p')
|
16
|
+
@descriptions = @doc.css('div.entry-document > div.entry-snippets > div.snippet')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruremasearcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruremasearcher"
|
8
|
+
spec.version = Ruremasearcher::VERSION
|
9
|
+
spec.authors = ["ryosy383"]
|
10
|
+
spec.email = ["mosso.ryosy383@gmail.com"]
|
11
|
+
spec.summary = %q{Search for in the Rurima-Search the method of Ruby.}
|
12
|
+
spec.description = %q{Search in http://rurema.clear-code.com/}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'ruremasearcher/version'
|
4
|
+
require 'auto_redirector'
|
5
|
+
require 'html_parser'
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
describe Ruremasearcher do
|
9
|
+
it 'should have a version number' do
|
10
|
+
Ruremasearcher::VERSION.should_not be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe AutoRedirector do
|
15
|
+
it 'valid redirect url' do
|
16
|
+
agent = 'Linux Firefox'
|
17
|
+
words = 'each map'
|
18
|
+
url = 'http://rurema.clear-code.com/'
|
19
|
+
ar = AutoRedirector.new(agent)
|
20
|
+
ar.get(url)
|
21
|
+
search_result = ar.search(words)
|
22
|
+
expect(search_result.uri.to_s).to eq('http://rurema.clear-code.com/query:each/query:map/')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe HtmlParser do
|
27
|
+
it 'valid html parse' do
|
28
|
+
html = <<-EOS
|
29
|
+
<?xml version="1.0" encoding="utf-8"?>
|
30
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
31
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
32
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
|
33
|
+
<head>
|
34
|
+
<div class="result">
|
35
|
+
<h2>検索結果</h2>
|
36
|
+
<div class="leading-link-box">
|
37
|
+
<h3 class="leading-link-title">
|
38
|
+
先頭5件
|
39
|
+
</h3>
|
40
|
+
<ol class="leading-links">
|
41
|
+
<li><a href="#entry-0">String<wbr />#<wbr />split(sep = <wbr />$<wbr />;<wbr />,<wbr /> limit = 0) -> [String] | [[String]]</a></li>
|
42
|
+
<li><a href="#entry-1">Pathname<wbr />#<wbr />split -> Array</a></li>
|
43
|
+
<li><a href="#entry-2">BigDecimal<wbr />#<wbr />split -> [Integer<wbr />,<wbr /> String<wbr />,<wbr /> Integer<wbr />,<wbr /> Integer]</a></li>
|
44
|
+
<li><a href="#entry-3">Shell<wbr />#<wbr />split(pathname) -> [String]</a></li>
|
45
|
+
<li><a href="#entry-4">Shell<wbr />::<wbr />CommandProcessor<wbr />#<wbr />split(pathname) -> [String]</a></li>
|
46
|
+
</ol>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
|
50
|
+
<dl class="entries">
|
51
|
+
<dt class="entry-name" id="entry-0">
|
52
|
+
<h3>
|
53
|
+
<span class="signature">
|
54
|
+
String<wbr />#<wbr />split(sep = <wbr />$<wbr />;<wbr />,<wbr /> limit = 0) -> [String] | [[String]]
|
55
|
+
</span>
|
56
|
+
<span class="score">(18222)</span>
|
57
|
+
</h3>
|
58
|
+
</dt>
|
59
|
+
<dd>
|
60
|
+
<ul class="entry-links">
|
61
|
+
<li class="entry-version">
|
62
|
+
<a href="http://docs.ruby-lang.org/ja/1.8.7/method/String/i/split.html">1.8.7</a>
|
63
|
+
</li>
|
64
|
+
<li class="entry-version">
|
65
|
+
<a href="http://docs.ruby-lang.org/ja/1.9.3/method/String/i/split.html">1.9.3</a>
|
66
|
+
</li>
|
67
|
+
<li class="entry-version">
|
68
|
+
<a href="http://docs.ruby-lang.org/ja/2.0.0/method/String/i/split.html">2.0.0</a>
|
69
|
+
</li>
|
70
|
+
<li class="entry-version">
|
71
|
+
<a href="http://docs.ruby-lang.org/ja/2.1.0/method/String/i/split.html">2.1.0</a>
|
72
|
+
</li>
|
73
|
+
</ul>
|
74
|
+
<ul class="entry-metadata">
|
75
|
+
<li class="entry-type">
|
76
|
+
<span class="entry-instance-method">
|
77
|
+
インスタンスメソッド
|
78
|
+
</span>
|
79
|
+
</li>
|
80
|
+
</ul>
|
81
|
+
<div class="entry-summary">
|
82
|
+
<p>
|
83
|
+
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
|
84
|
+
結果を文字列の配列で返します。</p>
|
85
|
+
</div>
|
86
|
+
<div class="entry-document">
|
87
|
+
<div class="entry-snippets">
|
88
|
+
<div class="snippet"><span class="separator">...</span>p " a \t b \n c".<span class="keyword">split</span>(/\s+/) # => ["", "a", "b", "c"]<br /><br /> p " a \t b \n c".<span class="keyword">split</span>(nil) # => ["a", "b", "c"]<br /> p " a \t b \n c".<span class="keyword">split</span>(' ') # => ["a", "b", "c"] #<span class="keyword"> split</span>(nil) と同じ<br /> p " a \t b \n c".<span class="keyword">split</span> # => ["a", "b", "c"] #<span class="keyword"> split</span>(nil) と同じ<br /><br /> #<span class="separator">...</span></div>
|
89
|
+
</div>
|
90
|
+
<div class="entry-snippets">
|
91
|
+
<div class="snippet"><span class="separator">...</span>p '1-10,20'.<span class="keyword">split</span>(/([-,])/) # => ["1", "-", "10", ",", "20"]<br /><br /> # 正規表現が空文字列にマッチする場合は 1 文字に分割<br /> p 'hi there'.<span class="keyword">split</span>(/\s*/).join(':') # => "h:i:t:h:e:r:e"<br /><br /> # 文字列全体を 1 文字ずつに分割する例<br /> p 'hi there'.<span class="keyword">split</span>(//).join(':'<span class="separator">...</span></div>
|
92
|
+
</div>
|
93
|
+
<div class="entry-snippets">
|
94
|
+
<div class="snippet"><span class="separator">...</span>'.<span class="keyword">split</span>(//).join(':') # => "文:字:列"<br /><br /> # limit == 0 だと制限なく分割、配列末尾の空文字列は取り除かれる<br /> p "a,b,c,,,".<span class="keyword">split</span>(/,/, 0) # => ["a", "b", "c"]<br /><br /> # limit 省略時は 0 と同じ (最もよく使われるパターン)<br /> p "a,b,c,,,".<span class="keyword">split</span>(/,/)<span class="separator">...</span></div>
|
95
|
+
</div>
|
96
|
+
<div class="entry-snippets">
|
97
|
+
<div class="snippet"><span class="separator">...</span>p "a,b,c,,,".<span class="keyword">split</span>(/,/, 0) # => ["a", "b", "c"]<br /><br /> # limit 省略時は 0 と同じ (最もよく使われるパターン)<br /> p "a,b,c,,,".<span class="keyword">split</span>(/,/) # => ["a", "b", "c"]<br /><br /> # 正の limit 使用例<br /> p "a,b,c,d,e".<span class="keyword">split</span>(/,/, 1) # => ["a,b,c,d,e"]<br /> p "a,b,c,d,e".<span class="keyword">split</span>(/,/, 2) # =<span class="separator">...</span></div>
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
<ul class="entry-related-entries">
|
101
|
+
<li class="entry-related-entry-class">
|
102
|
+
<a href="./class:String/">String</a>
|
103
|
+
</li>
|
104
|
+
<li class="entry-related-entry-query">
|
105
|
+
<a href="/ja/search/type:instance-method/query:String%23partition/">String#partition</a>
|
106
|
+
</li>
|
107
|
+
<li class="entry-related-entry-query">
|
108
|
+
<a href="/ja/search/type:instance-method/query:String%23rpartition/">String#rpartition</a>
|
109
|
+
</li>
|
110
|
+
</ul>
|
111
|
+
</dd>
|
112
|
+
<dt class="entry-name" id="entry-1">
|
113
|
+
<h3>
|
114
|
+
<span class="signature">
|
115
|
+
Pathname<wbr />#<wbr />split -> Array
|
116
|
+
</span>
|
117
|
+
<span class="score">(18124)</span>
|
118
|
+
</h3>
|
119
|
+
</dt>
|
120
|
+
</dl>
|
121
|
+
</body>
|
122
|
+
</html>
|
123
|
+
EOS
|
124
|
+
hp = HtmlParser.new(html)
|
125
|
+
hp.parse
|
126
|
+
expect(hp.titles[0].text.strip).to eq("String#split(sep = $;, limit = 0) -> [String] | [[String]]\n \n (18222)")
|
127
|
+
expect(hp.metadata[0].text.strip).to eq('インスタンスメソッド')
|
128
|
+
expect(hp.summaries[0].text.strip).to eq("第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、\n結果を文字列の配列で返します。")
|
129
|
+
expect(hp.descriptions[0].text.strip).to eq("...p \" a \t b \n c\".split(/ +/) # => [\"\", \"a\", \"b\", \"c\"] p \" a \t b \n c\".split(nil) # => [\"a\", \"b\", \"c\"] p \" a \t b \n c\".split(' ') # => [\"a\", \"b\", \"c\"] # split(nil) と同じ p \" a \t b \n c\".split # => [\"a\", \"b\", \"c\"] # split(nil) と同じ #...")
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter '/spec/'
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruremasearcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryosy383
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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
|
+
description: Search in http://rurema.clear-code.com/
|
56
|
+
email:
|
57
|
+
- mosso.ryosy383@gmail.com
|
58
|
+
executables:
|
59
|
+
- ruremasearcher
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".coveralls.yml"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".rubocop.yml"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/ruremasearcher
|
74
|
+
- lib/auto_redirector.rb
|
75
|
+
- lib/html_parser.rb
|
76
|
+
- lib/ruremasearcher/version.rb
|
77
|
+
- ruremasearcher.gemspec
|
78
|
+
- spec/ruremasearcher/ruremasearcher_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.2.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Search for in the Rurima-Search the method of Ruby.
|
104
|
+
test_files:
|
105
|
+
- spec/ruremasearcher/ruremasearcher_spec.rb
|
106
|
+
- spec/spec_helper.rb
|