Class: Syobocal::Comment::Section
- Inherits:
-
Object
- Object
- Syobocal::Comment::Section
show all
- Defined in:
- lib/syobocal/comment/section.rb
Defined Under Namespace
Classes: RestrictedOperation
Constant Summary
collapse
- STAFF_WORD =
"スタッフ"
- CAST_WORD =
"キャスト"
- LINK_WORD =
"リンク"
- MUSIC_WORDS =
%w(テーマ ソング 歌 曲)
- MUSIC_TITLE_REGEXP =
/\A(.*)「(.+?)」\Z/
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(header, elements) ⇒ Section
Returns a new instance of Section.
8
9
10
11
|
# File 'lib/syobocal/comment/section.rb', line 8
def initialize(, elements)
, @elements = , elements
@sub_sections = []
end
|
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
4
5
6
|
# File 'lib/syobocal/comment/section.rb', line 4
def elements
@elements
end
|
Returns the value of attribute header.
4
5
6
|
# File 'lib/syobocal/comment/section.rb', line 4
def
end
|
#sub_sections ⇒ Object
Returns the value of attribute sub_sections.
4
5
6
|
# File 'lib/syobocal/comment/section.rb', line 4
def sub_sections
@sub_sections
end
|
Class Method Details
.create_sections(elements) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/syobocal/comment/section.rb', line 90
def self.create_sections(elements)
sections = []
= nil
buffered_elements = []
elements.each do |element|
case element
when Element::, Element::
if
sections << Section.new(, buffered_elements)
buffered_elements = []
end
= element
else
buffered_elements << element if
end
end
if
sections << Section.new(, buffered_elements)
end
structure_sections(sections)
end
|
Instance Method Details
#add_subsection(sub_section) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/syobocal/comment/section.rb', line 17
def add_subsection(sub_section)
raise RestrictedOperation if sub_section?
raise RestrictedOperation unless sub_section.sub_section?
@sub_sections << sub_section
end
|
#cast_section? ⇒ Boolean
34
35
36
|
# File 'lib/syobocal/comment/section.rb', line 34
def cast_section?
.text_node.inner_text.include?(CAST_WORD)
end
|
#link_section? ⇒ Boolean
38
39
40
|
# File 'lib/syobocal/comment/section.rb', line 38
def link_section?
.text_node.inner_text.include?(LINK_WORD)
end
|
#links ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/syobocal/comment/section.rb', line 79
def links
elements.each_with_object([]) { |element, links|
case element
when Element::List
links << element.text_node.text_elements.select { |elm| elm.instance_of? Element::Link }
when Element::TextNode
links << element.text_elements.select { |elm| elm.instance_of? Element::Link }
end
}.flatten
end
|
#music_section? ⇒ Boolean
42
43
44
45
46
|
# File 'lib/syobocal/comment/section.rb', line 42
def music_section?
str = .text_node.inner_text
MUSIC_WORDS.any? { |keyword| str.include?(keyword) } && str.match(MUSIC_TITLE_REGEXP)
end
|
#rows ⇒ Object
75
76
77
|
# File 'lib/syobocal/comment/section.rb', line 75
def rows
elements.select { |element| element.is_a? Element::Row }
end
|
#staff_section? ⇒ Boolean
30
31
32
|
# File 'lib/syobocal/comment/section.rb', line 30
def staff_section?
.text_node.inner_text.include?(STAFF_WORD)
end
|
#sub_section? ⇒ Boolean
13
14
15
|
# File 'lib/syobocal/comment/section.rb', line 13
def sub_section?
.instance_of? Element::
end
|
#to_music ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/syobocal/comment/section.rb', line 48
def to_music
m = .text_node.inner_text.match(MUSIC_TITLE_REGEXP)
title = m[2]
category = m[1]
data_list = rows.map do |row|
attr = row.attr_node.inner_text
attr_fragment = Helper::Fragment.parse(attr)
if attr_fragment.to_a.size == 1
attr_text = attr_fragment.text
attr_note = attr_fragment&.child&.to_s
else
attr_text = attr_fragment.to_s
attr_note = nil
end
value = row.value_node.inner_text
people = Person.multi_parse(value)
MusicData.new(attr, attr_text, attr_note, value, people)
end
Music.new(title, category, data_list)
end
|