class SyoboiCalendar::CommentSection

Constants

PATTERN_NAME_CASTS
PATTERN_NAME_SONG_ENDING
PATTERN_NAME_SONG_INSERTED
PATTERN_NAME_SONG_OPENING
PATTERN_NAME_SONG_THEME
PATTERN_NAME_STAFFS
PATTERN_SONG_NAME
PATTERN_SONG_ROLE

Attributes

source[R]

Public Class Methods

new(source) click to toggle source

@param source [String]

# File lib/syoboi_calendar/comment_section.rb, line 15
def initialize(source)
  @source = source
end

Public Instance Methods

about_casts?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 20
def about_casts?
  PATTERN_NAME_CASTS === name
end
about_personalities?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 53
def about_personalities?
  about_casts? ||
    about_song? ||
    about_staffs?
end
about_song?() click to toggle source

@return [Boolean]

# 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?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 33
def about_song_ending?
  PATTERN_NAME_SONG_ENDING === name
end
about_song_inserted?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 38
def about_song_inserted?
  PATTERN_NAME_SONG_INSERTED === name
end
about_song_opening?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 43
def about_song_opening?
  PATTERN_NAME_SONG_OPENING === name
end
about_song_theme?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 48
def about_song_theme?
  PATTERN_NAME_SONG_THEME === name
end
about_staffs?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 60
def about_staffs?
  PATTERN_NAME_STAFFS === name
end
array() click to toggle source

@return [Array<String>]

# 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?() click to toggle source

@return [Boolean]

# File lib/syoboi_calendar/comment_section.rb, line 76
def has_hash?
  lines[1][0] == ":"
end
hash() click to toggle source

@return [Hash{String => String}]

# 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() click to toggle source

@return [Array<String>]

# File lib/syoboi_calendar/comment_section.rb, line 91
def lines
  source.strip.split("\n")
end
name() click to toggle source

@return [String]

# File lib/syoboi_calendar/comment_section.rb, line 96
def name
  lines[0][1..-1]
end
personalities() click to toggle source

@return [Array, nil]

# 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() click to toggle source

@return [Hash]

# File lib/syoboi_calendar/comment_section.rb, line 112
def song_attributes
  {
    name: song_name,
    role: song_role,
    personalities: personalities,
  }
end
song_name() click to toggle source

@return [String, nil]

# File lib/syoboi_calendar/comment_section.rb, line 121
def song_name
  if about_song?
    name[PATTERN_SONG_NAME, 1]
  end
end
song_role() click to toggle source

@return [String, nil]

# File lib/syoboi_calendar/comment_section.rb, line 128
def song_role
    name[PATTERN_SONG_ROLE, 1]
end