irasutoya 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +22 -0
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +50 -50
- data/README.md +9 -1
- data/irasutoya.gemspec +2 -1
- data/lib/irasutoya/irasuto.rb +8 -5
- data/lib/irasutoya/irasuto_link.rb +1 -1
- data/lib/irasutoya/modules/has_document_fetcher.rb +1 -0
- data/lib/irasutoya/modules/has_list_page_parser.rb +1 -0
- data/lib/irasutoya/modules/has_show_page_parser.rb +10 -2
- data/lib/irasutoya/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5a5b3dab5c783dcb0aa961cab26f390a0e54081bd81479d13e177f0c37fcf7
|
4
|
+
data.tar.gz: 8a2a78034c9839bdc3c9a20a73e2428dacee819bbe068e85107b792bae46294e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5979a9ab3500f788d6440857c8a1ec7f2c2fb1287106de4ae130322634c94580eb10177f08b0ddd1c3b1d3a400b6bdb0b388196c5b70c5eeef679fc926db0721
|
7
|
+
data.tar.gz: 2c92ca11d1cfea630d5578d891709c19ae42c20de65dfd52e81dfa4df88491e1014f8032199b5123a6d4809a45ae67ad87639f852e3a12e33fec95930dcf513e
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.6.x', '2.5.x', '2.4.x']
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@master
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: actions/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- name: Install bundler
|
18
|
+
run: gem install bundler
|
19
|
+
- name: Install dependencies
|
20
|
+
run: bundle install --jobs 4
|
21
|
+
- name: Run test
|
22
|
+
run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
irasutoya (1.
|
4
|
+
irasutoya (1.1.0)
|
5
5
|
nokogiri
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
11
|
-
codecov (0.
|
10
|
+
ast (2.4.1)
|
11
|
+
codecov (0.2.12)
|
12
12
|
json
|
13
13
|
simplecov
|
14
|
-
|
15
|
-
|
16
|
-
diff-lcs (1.3)
|
14
|
+
coderay (1.1.3)
|
15
|
+
diff-lcs (1.4.4)
|
17
16
|
docile (1.3.2)
|
18
|
-
ffi (1.
|
17
|
+
ffi (1.13.1)
|
19
18
|
formatador (0.2.5)
|
20
|
-
guard (2.
|
19
|
+
guard (2.16.2)
|
21
20
|
formatador (>= 0.2.4)
|
22
21
|
listen (>= 2.7, < 4.0)
|
23
22
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -34,63 +33,64 @@ GEM
|
|
34
33
|
guard-rubocop (1.3.0)
|
35
34
|
guard (~> 2.0)
|
36
35
|
rubocop (~> 0.20)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
rb-
|
41
|
-
|
42
|
-
|
43
|
-
lumberjack (1.0.13)
|
44
|
-
method_source (0.9.2)
|
36
|
+
json (2.3.1)
|
37
|
+
listen (3.2.1)
|
38
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
39
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
40
|
+
lumberjack (1.2.8)
|
41
|
+
method_source (1.0.0)
|
45
42
|
mini_portile2 (2.4.0)
|
46
43
|
nenv (0.3.0)
|
47
|
-
nokogiri (1.10.
|
44
|
+
nokogiri (1.10.10)
|
48
45
|
mini_portile2 (~> 2.4.0)
|
49
46
|
notiffany (0.1.3)
|
50
47
|
nenv (~> 0.1)
|
51
48
|
shellany (~> 0.0)
|
52
|
-
parallel (1.
|
53
|
-
parser (2.
|
54
|
-
ast (~> 2.4.
|
55
|
-
pry (0.
|
56
|
-
coderay (~> 1.1
|
57
|
-
method_source (~>
|
49
|
+
parallel (1.19.2)
|
50
|
+
parser (2.7.2.0)
|
51
|
+
ast (~> 2.4.1)
|
52
|
+
pry (0.13.1)
|
53
|
+
coderay (~> 1.1)
|
54
|
+
method_source (~> 1.0)
|
58
55
|
rainbow (3.0.0)
|
59
|
-
rake (
|
60
|
-
rb-fsevent (0.10.
|
61
|
-
rb-inotify (0.10.
|
56
|
+
rake (13.0.1)
|
57
|
+
rb-fsevent (0.10.4)
|
58
|
+
rb-inotify (0.10.1)
|
62
59
|
ffi (~> 1.0)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
rspec-
|
67
|
-
|
68
|
-
rspec-
|
69
|
-
rspec-
|
60
|
+
regexp_parser (1.8.2)
|
61
|
+
rexml (3.2.4)
|
62
|
+
rspec (3.9.0)
|
63
|
+
rspec-core (~> 3.9.0)
|
64
|
+
rspec-expectations (~> 3.9.0)
|
65
|
+
rspec-mocks (~> 3.9.0)
|
66
|
+
rspec-core (3.9.3)
|
67
|
+
rspec-support (~> 3.9.3)
|
68
|
+
rspec-expectations (3.9.2)
|
70
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
-
rspec-support (~> 3.
|
72
|
-
rspec-mocks (3.
|
70
|
+
rspec-support (~> 3.9.0)
|
71
|
+
rspec-mocks (3.9.1)
|
73
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
-
rspec-support (~> 3.
|
75
|
-
rspec-support (3.
|
76
|
-
rubocop (0.
|
77
|
-
jaro_winkler (~> 1.5.1)
|
73
|
+
rspec-support (~> 3.9.0)
|
74
|
+
rspec-support (3.9.3)
|
75
|
+
rubocop (0.93.1)
|
78
76
|
parallel (~> 1.10)
|
79
|
-
parser (>= 2.
|
77
|
+
parser (>= 2.7.1.5)
|
80
78
|
rainbow (>= 2.2.2, < 4.0)
|
79
|
+
regexp_parser (>= 1.8)
|
80
|
+
rexml
|
81
|
+
rubocop-ast (>= 0.6.0)
|
81
82
|
ruby-progressbar (~> 1.7)
|
82
|
-
unicode-display_width (>= 1.4.0, <
|
83
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
84
|
+
rubocop-ast (0.8.0)
|
85
|
+
parser (>= 2.7.1.5)
|
83
86
|
ruby-progressbar (1.10.1)
|
84
|
-
ruby_dep (1.5.0)
|
85
87
|
shellany (0.0.1)
|
86
|
-
simplecov (0.
|
88
|
+
simplecov (0.18.5)
|
87
89
|
docile (~> 1.1)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
unicode-display_width (1.6.0)
|
93
|
-
url (0.3.2)
|
90
|
+
simplecov-html (~> 0.11)
|
91
|
+
simplecov-html (0.12.3)
|
92
|
+
thor (1.0.1)
|
93
|
+
unicode-display_width (1.7.0)
|
94
94
|
|
95
95
|
PLATFORMS
|
96
96
|
ruby
|
@@ -102,7 +102,7 @@ DEPENDENCIES
|
|
102
102
|
guard-rspec
|
103
103
|
guard-rubocop
|
104
104
|
irasutoya!
|
105
|
-
rake (~>
|
105
|
+
rake (~> 13.0)
|
106
106
|
rspec (~> 3.0)
|
107
107
|
rubocop
|
108
108
|
simplecov
|
data/README.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# Irasutoya
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/irasutoya.svg)](https://badge.fury.io/rb/irasutoya)
|
4
|
+
[![Circle CI](https://circleci.com/gh/unhappychoice/irasutoya.svg?style=shield)](https://circleci.com/gh/unhappychoice/irasutoya)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/unhappychoice/irasutoya/badges/gpa.svg)](https://codeclimate.com/github/unhappychoice/irasutoya)
|
5
6
|
[![codecov](https://codecov.io/gh/unhappychoice/irasutoya/branch/master/graph/badge.svg)](https://codecov.io/gh/unhappychoice/irasutoya)
|
6
7
|
[![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/unhappychoice/irasutoya.svg)](https://libraries.io/github/unhappychoice/irasutoya)
|
7
8
|
![](http://ruby-gem-downloads-badge.herokuapp.com/irasutoya?type=total)
|
8
9
|
![GitHub](https://img.shields.io/github/license/unhappychoice/irasutoya.svg)
|
9
10
|
|
11
|
+
<p align="center">
|
12
|
+
<img src="https://1.bp.blogspot.com/-QU1PrEXerMg/XWS5ZxD-tsI/AAAAAAABUR4/1EuTP776BowewKdMAgnAUpUB5m3O7ve-ACLcBGAs/s1600/computer_screen_programming.png" width="400"/>
|
13
|
+
</p>
|
14
|
+
|
10
15
|
`Irasutoya` is ruby library for [いらすとや](https://www.irasutoya.com)
|
11
16
|
|
12
17
|
## Installation
|
@@ -25,6 +30,9 @@ irasuto.url
|
|
25
30
|
irasuto.title
|
26
31
|
irasuto.description
|
27
32
|
irasuto.image_url
|
33
|
+
irasuto.image_urls
|
34
|
+
irasuto.has_maltiple_images
|
35
|
+
irasuto.postthumb_image_url
|
28
36
|
|
29
37
|
irasuto_links = Irasutoya::Irasuto.search(query: 'おじさん', page: 3) #=> returns array of IrasutoLink instance
|
30
38
|
|
@@ -41,7 +49,7 @@ irasuto_link = irasuto_links.first
|
|
41
49
|
irasuto_link.title
|
42
50
|
irasuto_link.show_url
|
43
51
|
|
44
|
-
|
52
|
+
irasuto = irasuto_link.fetch_irasuto #=> returns Irasuto instance
|
45
53
|
```
|
46
54
|
|
47
55
|
## Contributing
|
data/irasutoya.gemspec
CHANGED
@@ -7,6 +7,7 @@ require 'irasutoya/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'irasutoya'
|
9
9
|
spec.version = Irasutoya::VERSION
|
10
|
+
spec.required_ruby_version = '>= 2.4'
|
10
11
|
spec.authors = ['Yuji Ueki']
|
11
12
|
spec.email = ['unhappychoice@gmail.com']
|
12
13
|
|
@@ -35,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
35
36
|
spec.add_development_dependency 'guard'
|
36
37
|
spec.add_development_dependency 'guard-rspec'
|
37
38
|
spec.add_development_dependency 'guard-rubocop'
|
38
|
-
spec.add_development_dependency 'rake', '~>
|
39
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
39
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
41
|
spec.add_development_dependency 'rubocop'
|
41
42
|
spec.add_development_dependency 'simplecov'
|
data/lib/irasutoya/irasuto.rb
CHANGED
@@ -6,13 +6,16 @@ module Irasutoya
|
|
6
6
|
include Modules::HasListPageParser
|
7
7
|
include Modules::HasShowPageParser
|
8
8
|
|
9
|
-
attr_reader :url, :title, :description, :image_url
|
9
|
+
attr_reader :url, :title, :description, :image_urls, :postthumb_image_url, :image_url, :has_multiple_images
|
10
10
|
|
11
|
-
def initialize(url:, title:, description:,
|
11
|
+
def initialize(url:, title:, description:, image_urls:)
|
12
12
|
@url = url
|
13
13
|
@title = title
|
14
14
|
@description = description
|
15
|
-
@
|
15
|
+
@image_urls = image_urls
|
16
|
+
@has_multiple_images = image_urls.size > 1
|
17
|
+
@postthumb_image_url = image_urls.first if @has_multiple_images
|
18
|
+
@image_url = image_urls.first
|
16
19
|
end
|
17
20
|
|
18
21
|
class << self
|
@@ -21,7 +24,7 @@ module Irasutoya
|
|
21
24
|
document = fetch_page_and_parse(url)
|
22
25
|
parsed = parse_show_page(document: document)
|
23
26
|
|
24
|
-
Irasuto.new(url: url, title: parsed[:title], description: parsed[:description],
|
27
|
+
Irasuto.new(url: url, title: parsed[:title], description: parsed[:description], image_urls: parsed[:image_urls])
|
25
28
|
end
|
26
29
|
|
27
30
|
def search(query:, page: 0)
|
@@ -47,7 +50,7 @@ module Irasutoya
|
|
47
50
|
|
48
51
|
def random_url
|
49
52
|
jsonp = Net::HTTP.get('www.irasutoya.com', random_api_path)
|
50
|
-
JSON.parse(jsonp[/{.+}/])
|
53
|
+
JSON.parse(jsonp[/{.+}/]) # rubocop:disable Style/SingleArgumentDig
|
51
54
|
.dig('feed', 'entry')
|
52
55
|
.first
|
53
56
|
.dig('link')
|
@@ -4,6 +4,7 @@ module Irasutoya
|
|
4
4
|
module Modules
|
5
5
|
module HasShowPageParser
|
6
6
|
def self.included(klass)
|
7
|
+
super
|
7
8
|
klass.send(:include, Irasutoya::Modules::HasShowPageParser::Methods)
|
8
9
|
klass.send(:extend, Irasutoya::Modules::HasShowPageParser::Methods)
|
9
10
|
end
|
@@ -13,7 +14,7 @@ module Irasutoya
|
|
13
14
|
{
|
14
15
|
title: PrivateMethods.title_from(document: document),
|
15
16
|
description: PrivateMethods.description_from(document: document),
|
16
|
-
|
17
|
+
image_urls: PrivateMethods.image_urls_from(document: document)
|
17
18
|
}
|
18
19
|
end
|
19
20
|
end
|
@@ -30,7 +31,14 @@ module Irasutoya
|
|
30
31
|
|
31
32
|
def image_url_from(document:)
|
32
33
|
image = document.css('.entry').search('img').attribute('src').value
|
33
|
-
image.chars.first == '/' ?
|
34
|
+
image.chars.first == '/' ? "https:#{image}" : image
|
35
|
+
end
|
36
|
+
|
37
|
+
def image_urls_from(document:)
|
38
|
+
sources = document.css('.entry').search('img').collect do |img|
|
39
|
+
img[:src]
|
40
|
+
end
|
41
|
+
sources.collect { |url| url.start_with?('/') ? "https:#{url}" : url }
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/irasutoya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irasutoya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Ueki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '13.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '13.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,6 +158,7 @@ extensions: []
|
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
160
|
- ".circleci/config.yml"
|
161
|
+
- ".github/workflows/test.yml"
|
161
162
|
- ".rspec"
|
162
163
|
- ".rubocop.yml"
|
163
164
|
- ".rubocop_todo.yml"
|
@@ -193,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
194
|
requirements:
|
194
195
|
- - ">="
|
195
196
|
- !ruby/object:Gem::Version
|
196
|
-
version: '
|
197
|
+
version: '2.4'
|
197
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
199
|
requirements:
|
199
200
|
- - ">="
|