Class: SyoboiCalendar::CommentSection
- Inherits:
-
Object
- Object
- SyoboiCalendar::CommentSection
- Defined in:
- lib/syoboi_calendar/comment_section.rb
Constant Summary collapse
- PATTERN_NAME_CASTS =
"キャスト"
- PATTERN_NAME_STAFFS =
"スタッフ"
- PATTERN_NAME_SONG_ENDING =
/\Aエンディング\d*\s*「(.+)」\z/
- PATTERN_NAME_SONG_INSERTED =
/\A挿入歌\d*\s*「(.+)」\z/
- PATTERN_NAME_SONG_OPENING =
/\Aオープニング\d*\s*「(.+)」\z/
- PATTERN_NAME_SONG_THEME =
/\A主題歌\d*\s*「(.+)」\z/
- PATTERN_SONG_NAME =
/「(.+)」/
- PATTERN_SONG_ROLE =
/(\S+)\s*「.+」/
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #about_casts? ⇒ Boolean
- #about_personalities? ⇒ Boolean
- #about_song? ⇒ Boolean
- #about_song_ending? ⇒ Boolean
- #about_song_inserted? ⇒ Boolean
- #about_song_opening? ⇒ Boolean
- #about_song_theme? ⇒ Boolean
- #about_staffs? ⇒ Boolean
- #array ⇒ Array<String>
- #has_hash? ⇒ Boolean
- #hash ⇒ Hash{String => String}
-
#initialize(source) ⇒ CommentSection
constructor
A new instance of CommentSection.
- #lines ⇒ Array<String>
- #name ⇒ String
- #personalities ⇒ Array?
- #song_attributes ⇒ Hash
- #song_name ⇒ String?
- #song_role ⇒ String?
Constructor Details
#initialize(source) ⇒ CommentSection
Returns a new instance of CommentSection.
15 16 17 |
# File 'lib/syoboi_calendar/comment_section.rb', line 15 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
12 13 14 |
# File 'lib/syoboi_calendar/comment_section.rb', line 12 def source @source end |
Instance Method Details
#about_casts? ⇒ Boolean
20 21 22 |
# File 'lib/syoboi_calendar/comment_section.rb', line 20 def about_casts? PATTERN_NAME_CASTS === name end |
#about_personalities? ⇒ Boolean
53 54 55 56 57 |
# File 'lib/syoboi_calendar/comment_section.rb', line 53 def about_personalities? about_casts? || about_song? || about_staffs? end |
#about_song? ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/syoboi_calendar/comment_section.rb', line 25 def about_song? about_song_ending? || about_song_inserted? || about_song_opening? || about_song_theme? end |
#about_song_ending? ⇒ Boolean
33 34 35 |
# File 'lib/syoboi_calendar/comment_section.rb', line 33 def about_song_ending? PATTERN_NAME_SONG_ENDING === name end |
#about_song_inserted? ⇒ Boolean
38 39 40 |
# File 'lib/syoboi_calendar/comment_section.rb', line 38 def about_song_inserted? PATTERN_NAME_SONG_INSERTED === name end |
#about_song_opening? ⇒ Boolean
43 44 45 |
# File 'lib/syoboi_calendar/comment_section.rb', line 43 def about_song_opening? PATTERN_NAME_SONG_OPENING === name end |
#about_song_theme? ⇒ Boolean
48 49 50 |
# File 'lib/syoboi_calendar/comment_section.rb', line 48 def about_song_theme? PATTERN_NAME_SONG_THEME === name end |
#about_staffs? ⇒ Boolean
60 61 62 |
# File 'lib/syoboi_calendar/comment_section.rb', line 60 def about_staffs? PATTERN_NAME_STAFFS === name end |
#array ⇒ Array<String>
65 66 67 68 69 70 71 72 73 |
# File 'lib/syoboi_calendar/comment_section.rb', line 65 def array if lines[1][0] == "-" lines[1..-1].grep(/\A-/).map do |line| line[1..-1] end else lines end end |
#has_hash? ⇒ Boolean
76 77 78 |
# File 'lib/syoboi_calendar/comment_section.rb', line 76 def has_hash? lines[1][0] == ":" end |
#hash ⇒ Hash{String => String}
81 82 83 84 85 86 87 88 |
# File 'lib/syoboi_calendar/comment_section.rb', line 81 def hash lines[1..-1].grep(/\A:/).each_with_object({}) do |line, result| key, value = line[1..-1].split(/[::]/, 2) if value result[key] = value.split("、") end end end |
#lines ⇒ Array<String>
91 92 93 |
# File 'lib/syoboi_calendar/comment_section.rb', line 91 def lines source.strip.split("\n") end |
#name ⇒ String
96 97 98 |
# File 'lib/syoboi_calendar/comment_section.rb', line 96 def name lines[0][1..-1] end |
#personalities ⇒ Array?
101 102 103 104 105 106 107 108 109 |
# File 'lib/syoboi_calendar/comment_section.rb', line 101 def personalities if about_personalities? hash.flat_map do |role, sources| sources.map do |source| ::SyoboiCalendar::Personality.new(role: role, source: source) end end end end |
#song_attributes ⇒ Hash
112 113 114 115 116 117 118 |
# File 'lib/syoboi_calendar/comment_section.rb', line 112 def song_attributes { name: song_name, role: song_role, personalities: personalities, } end |
#song_name ⇒ String?
121 122 123 124 125 |
# File 'lib/syoboi_calendar/comment_section.rb', line 121 def song_name if about_song? name[PATTERN_SONG_NAME, 1] end end |
#song_role ⇒ String?
128 129 130 |
# File 'lib/syoboi_calendar/comment_section.rb', line 128 def song_role name[PATTERN_SONG_ROLE, 1] end |