Class: Syobocal::Comment::Parser
- Inherits:
-
Object
- Object
- Syobocal::Comment::Parser
- Defined in:
- lib/syobocal/comment/parser.rb
Constant Summary collapse
- ELEMENT_CLASSES =
[ Element::Header2, Element::Header1, Element::List, Element::Row, Element::Blank, Element::TextNode, # NOTE Sentinel ]
Instance Method Summary collapse
- #all_sections ⇒ Object
- #casts ⇒ Object
-
#initialize(comment) ⇒ Parser
constructor
A new instance of Parser.
- #links ⇒ Object
- #musics ⇒ Object
- #parse ⇒ Object
- #sections ⇒ Object
- #staffs ⇒ Object
Constructor Details
#initialize(comment) ⇒ Parser
Returns a new instance of Parser.
13 14 15 |
# File 'lib/syobocal/comment/parser.rb', line 13 def initialize(comment) @comment = comment end |
Instance Method Details
#all_sections ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
38 39 40 41 42 43 44 |
# 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 |
#links ⇒ Object
52 53 54 55 56 |
# File 'lib/syobocal/comment/parser.rb', line 52 def links return @links if defined? @links @links = sections.find { |section| section.link_section? }&.links || [] end |
#musics ⇒ Object
46 47 48 49 50 |
# File 'lib/syobocal/comment/parser.rb', line 46 def musics return @musics if defined? @musics @musics = create_musics(all_sections) end |
#parse ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 ⇒ Object
58 59 60 61 62 |
# File 'lib/syobocal/comment/parser.rb', line 58 def sections return @sections if defined? @sections @sections = Section.create_sections(parse.elements) end |
#staffs ⇒ Object
30 31 32 33 34 35 36 |
# 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 |