class Syobocal::Comment::Parser

Constants

ELEMENT_CLASSES

Public Class Methods

new(comment) click to toggle source
# File lib/syobocal/comment/parser.rb, line 13
def initialize(comment)
  @comment = comment
end

Public Instance Methods

all_sections() { |section| ... } click to toggle source
# File lib/syobocal/comment/parser.rb, line 64
def all_sections
  return enum_for(:all_sections) unless block_given?

  sections.each do |section|
    yield section

    section.sub_sections.each do |sub_section|
      yield sub_section
    end
  end
end
casts() click to toggle source
# File lib/syobocal/comment/parser.rb, line 38
def casts
  return @casts if defined? @casts

  rows = sections.find { |section| section.cast_section? }&.rows || []

  @casts = create_cast_list(rows)
end
musics() click to toggle source
# File lib/syobocal/comment/parser.rb, line 46
def musics
  return @musics if defined? @musics

  @musics = create_musics(all_sections)
end
parse() click to toggle source
# File lib/syobocal/comment/parser.rb, line 17
def parse
  return @parse if defined? @parse

  return @parse = Element::Root.new([]) unless @comment

  elements = @comment.each_line.map do |line|
    line.chomp!
    ELEMENT_CLASSES.find { |clazz| clazz.match?(line) }.parse(line)
  end

  @parse = Element::Root.new(elements)
end
sections() click to toggle source
# File lib/syobocal/comment/parser.rb, line 58
def sections
  return @sections if defined? @sections

  @sections = Section.create_sections(parse.elements)
end
staffs() click to toggle source
# File lib/syobocal/comment/parser.rb, line 30
def staffs
  return @staffs if defined? @staffs

  rows = sections.find { |section| section.staff_section? }&.rows || []

  @staffs = create_staff_list(rows)
end

Private Instance Methods

create_cast_list(rows) click to toggle source
# File lib/syobocal/comment/parser.rb, line 87
def create_cast_list(rows)
  rows.map do |row|
    character = row.attr_node.inner_text
    people = row.value_node.split.map { |str| Person.parse(str) }

    Cast.new(character, people)
  end
end
create_musics(sections) click to toggle source
# File lib/syobocal/comment/parser.rb, line 96
def create_musics(sections)
  sections.each_with_object([]) do |section, musics|
    musics << section.to_music if section.music_section?
  end
end
create_staff_list(rows) click to toggle source
# File lib/syobocal/comment/parser.rb, line 78
def create_staff_list(rows)
  rows.map do |row|
    role = row.attr_node.inner_text
    people = row.value_node.split.map { |str| Person.parse(str) }

    Staff.new(role, people)
  end
end