syobocal 0.12.0 → 0.15.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: d0398de2d798888a3de127fc65f3d5b7e80571e9ce0fb14a5167787dae9714d4
4
- data.tar.gz: 4851e93fe58065998cbecba8ea6c598b2e0971c145a755157636aa5f2f91ed11
3
+ metadata.gz: a7c70f8c43481ff45aa94a288afc6efa6148e54bc5e2e30013c54a3e298f873b
4
+ data.tar.gz: 60692a1fbdf68e2f4acded6208706a1ac86e9d6934eb72f25858b9d12cd512ca
5
5
  SHA512:
6
- metadata.gz: 4b617073199d1f4e2ecb320e908d9874cbc67ad4a3154b268ff35466712397f4e802b07aa4fd30697f5803feb2cea9bbae3b2f92cfd7ea3d0f5a04c8536e9603
7
- data.tar.gz: 3d8cde4777e1de49b68fcf533e3171fbc658e48292ab75970c428ed5dcadc8302d0fe37d428492c7fe34a9dfa86072abedc115d005472c8a0b2f339f66b61411
6
+ metadata.gz: 3b2733ca8dd5ebaa5b7b52b84cc44235da6f460bf7516e647e12ae4225df629d6d2e8e45a914681671d53b5886d6fbdbadcee6ce3c77f5a7c0cc9e8c177bd622
7
+ data.tar.gz: d18ea750bc40dfc21b0a791df14d32fdc35a3fd49c460808922d205c36d229afd7fa4785b835a1539f81a35bf2578e70bcab2e92f1a752efb21a6f96a00e70b7
data/README.md CHANGED
@@ -135,20 +135,39 @@ pp parser.casts.first
135
135
  # [#<Syobocal::Comment::Person:0x0000564600051cd8 @name="悠木碧", @note=nil>]>
136
136
 
137
137
  pp parser.musics.first
138
- # #<Syobocal::Comment::Music:0x00005646000afc98
138
+ # #<Syobocal::Comment::Music:0x0000561287c8f1a0
139
139
  # @category="オープニングテーマ",
140
140
  # @data_list=
141
- # [#<Syobocal::Comment::MusicData:0x00005646000a0b30
141
+ # [#<Syobocal::Comment::MusicData:0x0000561287c8b8e8
142
142
  # @attr="作詞・作曲",
143
+ # @attr_note=nil,
144
+ # @attr_text="作詞・作曲",
145
+ # @people=
146
+ # [#<Syobocal::Comment::Person:0x0000561287c8ba28 @name="渡辺翔", @note=nil>],
143
147
  # @value="渡辺翔">,
144
- # #<Syobocal::Comment::MusicData:0x00005646000a06a8
148
+ # #<Syobocal::Comment::MusicData:0x0000561287c8a3d0
145
149
  # @attr="主題歌協力",
150
+ # @attr_note=nil,
151
+ # @attr_text="主題歌協力",
152
+ # @people=
153
+ # [#<Syobocal::Comment::Person:0x0000561287c8a510 @name="外村敬一", @note=nil>],
146
154
  # @value="外村敬一">,
147
- # #<Syobocal::Comment::MusicData:0x00005646000a0428
155
+ # #<Syobocal::Comment::MusicData:0x0000561287c88e90
148
156
  # @attr="歌",
157
+ # @attr_note=nil,
158
+ # @attr_text="歌",
159
+ # @people=
160
+ # [#<Syobocal::Comment::Person:0x0000561287c88fd0
161
+ # @name="ClariS",
162
+ # @note=nil>],
149
163
  # @value="ClariS">,
150
- # #<Syobocal::Comment::MusicData:0x00005646000afd38
164
+ # #<Syobocal::Comment::MusicData:0x0000561287c8f2e0
151
165
  # @attr="使用話数",
166
+ # @attr_note=nil,
167
+ # @attr_text="使用話数",
168
+ # @people=
169
+ # [#<Syobocal::Comment::Person:0x0000561287c8f560 @name="#1~#9", @note=nil>,
170
+ # #<Syobocal::Comment::Person:0x0000561287c8f420 @name="#11", @note=nil>],
152
171
  # @value="#1~#9、#11">],
153
172
  # @title="コネクト">
154
173
  ```
@@ -1,7 +1,7 @@
1
1
  module Syobocal
2
2
  module CalChk
3
3
  def get(params = {})
4
- parse(open(url(params)))
4
+ parse(URI.open(url(params)))
5
5
  end
6
6
 
7
7
  def url(params = {})
@@ -0,0 +1,80 @@
1
+ module Syobocal
2
+ module Comment
3
+ module Helper
4
+ class Fragment
5
+ CHILD_BEGIN = "("
6
+ CHILD_END = ")"
7
+ SEPARATOR = "、"
8
+
9
+ attr_reader :text, :child, :following
10
+
11
+ def initialize(text, child, following)
12
+ @text, @child, @following = text, child, following
13
+ end
14
+
15
+ def self.parse(str)
16
+ chars = str.each_char.to_a
17
+
18
+ parse_chars(chars)
19
+ end
20
+
21
+ def self.parse_chars(chars)
22
+ text = ""
23
+ child = nil
24
+ following = nil
25
+
26
+ until chars.empty?
27
+ c = chars.shift
28
+
29
+ case c
30
+ when CHILD_BEGIN
31
+ child = parse_chars(chars)
32
+ when CHILD_END
33
+ return Fragment.new(text, child, following)
34
+ when SEPARATOR
35
+ following = parse_chars(chars)
36
+ else
37
+ text << c
38
+ end
39
+ end
40
+
41
+ Fragment.new(text, child, following)
42
+ end
43
+
44
+ def pretty_output(level = 0)
45
+ line = level.times.map { " " }.join
46
+
47
+ line << text
48
+
49
+ puts line
50
+
51
+ child&.pretty_output(level + 1)
52
+
53
+ following&.pretty_output(level)
54
+ end
55
+
56
+ def to_a
57
+ array = [self]
58
+ target = self
59
+
60
+ while target.following
61
+ array << target.following
62
+ target = target.following
63
+ end
64
+
65
+ array
66
+ end
67
+
68
+ def to_s
69
+ to_a.map { |f|
70
+ if f.child
71
+ "#{f.text}(#{f.child.to_s})"
72
+ else
73
+ "#{f.text}"
74
+ end
75
+ }.join(SEPARATOR)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,14 +1,14 @@
1
1
  module Syobocal
2
2
  module Comment
3
3
  class MusicData
4
- attr_reader :attr, :value
4
+ attr_reader :attr, :attr_text, :attr_note, :value, :people
5
5
 
6
- def initialize(attr, value)
7
- @attr, @value = attr, value
6
+ def initialize(attr, attr_text, attr_note, value, people)
7
+ @attr, @attr_text, @attr_note, @value, @people = attr, attr_text, attr_note, value, people
8
8
  end
9
9
 
10
10
  def ==(other)
11
- other.instance_of?(self.class) && other.attr == attr && other.value == value
11
+ other.instance_of?(self.class) && other.attr == attr && other.attr_text == attr_text && other.attr_note == other.attr_note && other.value == value && other.people == people
12
12
  end
13
13
  end
14
14
  end
@@ -76,21 +76,25 @@ module Syobocal
76
76
  private
77
77
 
78
78
  def create_staff_list(rows)
79
- rows.map do |row|
79
+ staffs = rows.map do |row|
80
80
  role = row.attr_node.inner_text
81
81
  people = row.value_node.split.map { |str| Person.parse(str) }
82
82
 
83
- Staff.new(role, people)
83
+ Staff.new(role, people.select(&:valid?))
84
84
  end
85
+
86
+ staffs.select { |staff| !staff.people.empty? }
85
87
  end
86
88
 
87
89
  def create_cast_list(rows)
88
- rows.map do |row|
90
+ casts = rows.map do |row|
89
91
  character = row.attr_node.inner_text
90
92
  people = row.value_node.split.map { |str| Person.parse(str) }
91
93
 
92
- Cast.new(character, people)
94
+ Cast.new(character, people.select(&:valid?))
93
95
  end
96
+
97
+ casts.select { |cast| !cast.people.empty? }
94
98
  end
95
99
 
96
100
  def create_musics(sections)
@@ -14,10 +14,23 @@ module Syobocal
14
14
  other.instance_of?(self.class) && other.name == name && other.note == note
15
15
  end
16
16
 
17
+ def valid?
18
+ !name.nil? && !name.empty?
19
+ end
20
+
17
21
  def self.parse(str)
18
22
  _, name, note = *(str.match(/\A([^\(\)]+?)(?:\((.*?)\))?\Z/).to_a)
19
23
 
20
- Person.new(name, note)
24
+ Person.new(name&.strip, note&.strip)
25
+ end
26
+
27
+ def self.multi_parse(str)
28
+ Helper::Fragment.parse(str).to_a.map { |f|
29
+ name = f.text
30
+ note = f&.child&.to_s
31
+
32
+ Person.new(name, note)
33
+ }
21
34
  end
22
35
  end
23
36
  end
@@ -52,8 +52,21 @@ module Syobocal
52
52
 
53
53
  data_list = rows.map do |row|
54
54
  attr = row.attr_node.inner_text
55
+
56
+ attr_fragment = Helper::Fragment.parse(attr)
57
+
58
+ if attr_fragment.to_a.size == 1
59
+ attr_text = attr_fragment.text
60
+ attr_note = attr_fragment&.child&.to_s
61
+ else
62
+ attr_text = attr_fragment.to_s
63
+ attr_note = nil
64
+ end
65
+
55
66
  value = row.value_node.inner_text
56
- MusicData.new(attr, value)
67
+ people = Person.multi_parse(value)
68
+
69
+ MusicData.new(attr, attr_text, attr_note, value, people)
57
70
  end
58
71
 
59
72
  Music.new(title, category, data_list)
data/lib/syobocal/db.rb CHANGED
@@ -36,7 +36,7 @@ module Syobocal
36
36
 
37
37
  module TitleLookup
38
38
  def get(params = {})
39
- parse(open(url(params)))
39
+ parse(URI.open(url(params)))
40
40
  end
41
41
 
42
42
  def url(params)
@@ -91,7 +91,7 @@ module Syobocal
91
91
 
92
92
  module ProgLookup
93
93
  def get(params = {})
94
- parse(open(url(params)))
94
+ parse(URI.open(url(params)))
95
95
  end
96
96
 
97
97
  def url(params)
@@ -143,7 +143,7 @@ module Syobocal
143
143
 
144
144
  module ChLookup
145
145
  def get(params = {})
146
- parse(open(url(params)))
146
+ parse(URI.open(url(params)))
147
147
  end
148
148
 
149
149
  def url(params)
@@ -189,7 +189,7 @@ module Syobocal
189
189
 
190
190
  module ChGroupLookup
191
191
  def get(params = {})
192
- parse(open(url(params)))
192
+ parse(URI.open(url(params)))
193
193
  end
194
194
 
195
195
  def url(params)
@@ -231,7 +231,7 @@ module Syobocal
231
231
 
232
232
  module TitleViewCount
233
233
  def get(params = {})
234
- parse(open(url(params)))
234
+ parse(URI.open(url(params)))
235
235
  end
236
236
 
237
237
  def url(params)
@@ -247,7 +247,7 @@ module Syobocal
247
247
 
248
248
  module TitleRankHistory
249
249
  def get(params = {})
250
- parse(open(url(params)))
250
+ parse(URI.open(url(params)))
251
251
  end
252
252
 
253
253
  def url(params)
@@ -263,7 +263,7 @@ module Syobocal
263
263
 
264
264
  module TitlePointHistory
265
265
  def get(params = {})
266
- parse(open(url(params)))
266
+ parse(URI.open(url(params)))
267
267
  end
268
268
 
269
269
  def url(params)
@@ -279,7 +279,7 @@ module Syobocal
279
279
 
280
280
  module TitlePointTop
281
281
  def get(params = {})
282
- parse(open(url(params)))
282
+ parse(URI.open(url(params)))
283
283
  end
284
284
 
285
285
  def url(params)
data/lib/syobocal/json.rb CHANGED
@@ -2,7 +2,7 @@ module Syobocal
2
2
  module JSON
3
3
  module TitleMedium
4
4
  def get(params = {})
5
- parse(open(url(params)))
5
+ parse(URI.open(url(params)))
6
6
  end
7
7
 
8
8
  def url(params = {})
@@ -18,7 +18,7 @@ module Syobocal
18
18
 
19
19
  module TitleLarge
20
20
  def get(params = {})
21
- parse(open(url(params)))
21
+ parse(URI.open(url(params)))
22
22
  end
23
23
 
24
24
  def url(params = {})
@@ -34,7 +34,7 @@ module Syobocal
34
34
 
35
35
  module TitleFull
36
36
  def get(params = {})
37
- parse(open(url(params)))
37
+ parse(URI.open(url(params)))
38
38
  end
39
39
 
40
40
  def url(params = {})
@@ -50,7 +50,7 @@ module Syobocal
50
50
 
51
51
  module ProgramByPID
52
52
  def get(params = {})
53
- parse(open(url(params)))
53
+ parse(URI.open(url(params)))
54
54
  end
55
55
 
56
56
  def url(params = {})
@@ -66,7 +66,7 @@ module Syobocal
66
66
 
67
67
  module ProgramByCount
68
68
  def get(params = {})
69
- parse(open(url(params)))
69
+ parse(URI.open(url(params)))
70
70
  end
71
71
 
72
72
  def url(params = {})
@@ -82,7 +82,7 @@ module Syobocal
82
82
 
83
83
  module ProgramByDate
84
84
  def get(params = {})
85
- parse(open(url(params)))
85
+ parse(URI.open(url(params)))
86
86
  end
87
87
 
88
88
  def url(params = {})
@@ -98,7 +98,7 @@ module Syobocal
98
98
 
99
99
  module SubTitles
100
100
  def get(params = {})
101
- parse(open(url(params)))
101
+ parse(URI.open(url(params)))
102
102
  end
103
103
 
104
104
  def url(params = {})
@@ -114,7 +114,7 @@ module Syobocal
114
114
 
115
115
  module ChFilter
116
116
  def get(params = {})
117
- parse(open(url(params)))
117
+ parse(URI.open(url(params)))
118
118
  end
119
119
 
120
120
  def url(params = {})
@@ -130,7 +130,7 @@ module Syobocal
130
130
 
131
131
  module ChIDFilter
132
132
  def get(params = {})
133
- parse(open(url(params)))
133
+ parse(URI.open(url(params)))
134
134
  end
135
135
 
136
136
  def url(params = {})
data/lib/syobocal/rss.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Syobocal
2
2
  module RSS
3
3
  def get(params = {})
4
- parse(open(url(params)))
4
+ parse(URI.open(url(params)))
5
5
  end
6
6
 
7
7
  def url(params = {})
data/lib/syobocal/rss2.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Syobocal
2
2
  module RSS2
3
3
  def get(params = {})
4
- parse(open(url(params)))
4
+ parse(URI.open(url(params)))
5
5
  end
6
6
 
7
7
  def url(params = {})
@@ -10,7 +10,7 @@ module Syobocal
10
10
  def parse
11
11
  return @parse if defined? @parse
12
12
 
13
- @sub_titles.each_line.each_with_object([]){|line, array|
13
+ @sub_titles.each_line.each_with_object([]) { |line, array|
14
14
  m = FORMAT_REGEXP.match(line)
15
15
 
16
16
  array << SubTitle.new(m[1], m[2]) if m
@@ -1,3 +1,3 @@
1
1
  module Syobocal
2
- VERSION = "0.12.0"
2
+ VERSION = "0.15.0"
3
3
  end
data/lib/syobocal.rb CHANGED
@@ -20,6 +20,7 @@ require "syobocal/comment/element/row"
20
20
  require "syobocal/comment/element/text"
21
21
  require "syobocal/comment/element/text_node"
22
22
  require "syobocal/comment/element/root"
23
+ require "syobocal/comment/helper/fragment"
23
24
  require "syobocal/comment/parser"
24
25
  require "syobocal/comment/staff"
25
26
  require "syobocal/comment/cast"
data/syobocal.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "syobocal/version"
@@ -24,7 +23,11 @@ Gem::Specification.new do |spec|
24
23
  spec.require_paths = ["lib"]
25
24
 
26
25
  spec.add_development_dependency "bundler", "~> 2.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rake", ">= 13.0"
28
27
  spec.add_development_dependency "minitest", "~> 5.0"
29
28
  spec.add_development_dependency "rufo", "~> 0.7"
29
+ spec.add_dependency "rexml", "~> 3.2"
30
+ spec.add_dependency "rss", "~> 0.2"
31
+
32
+ spec.required_ruby_version = ">= 3.1.0"
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syobocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xmisao
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-10 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rexml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rss
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
69
97
  description: Syoboi Calendar is the oldest and biggest ANIME information site, supported
70
98
  and hosted by anime fans in Japan. This gem make it easy to download information
71
99
  using web APIs of this site.
@@ -100,6 +128,7 @@ files:
100
128
  - lib/syobocal/comment/element/row.rb
101
129
  - lib/syobocal/comment/element/text.rb
102
130
  - lib/syobocal/comment/element/text_node.rb
131
+ - lib/syobocal/comment/helper/fragment.rb
103
132
  - lib/syobocal/comment/music.rb
104
133
  - lib/syobocal/comment/music_data.rb
105
134
  - lib/syobocal/comment/parser.rb
@@ -121,7 +150,7 @@ homepage: https://github.com/xmisao/syobocal
121
150
  licenses:
122
151
  - MIT
123
152
  metadata: {}
124
- post_install_message:
153
+ post_install_message:
125
154
  rdoc_options: []
126
155
  require_paths:
127
156
  - lib
@@ -129,15 +158,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
158
  requirements:
130
159
  - - ">="
131
160
  - !ruby/object:Gem::Version
132
- version: '0'
161
+ version: 3.1.0
133
162
  required_rubygems_version: !ruby/object:Gem::Requirement
134
163
  requirements:
135
164
  - - ">="
136
165
  - !ruby/object:Gem::Version
137
166
  version: '0'
138
167
  requirements: []
139
- rubygems_version: 3.0.3
140
- signing_key:
168
+ rubygems_version: 3.3.7
169
+ signing_key:
141
170
  specification_version: 4
142
171
  summary: Simple gem for Syoboi Calendar
143
172
  test_files: []