lib/scrivstats/scriven.rb
def parse
      # parse the project and compute statistics
      xml = File.read(scrivx)
      doc = Nokogiri::Slop(xml)
      binder_items = doc.ScrivenerProject.Binder.BinderItem
      manu = binder_items.detect { |el| el.Title.content == 'Manuscript' }
      chapter_nodes = manu.Children.BinderItem.select { |el| el.Title.content.match('Chapter') }
      chapter_nodes.each do |chapter_node|
        title = chapter_node.Title.content
        id = chapter_node['ID']
        chapter = Chapter.new(id, title)
        add_chapter(chapter)
        node = chapter_node.Children.BinderItem("[Type='Text']")
        if node.class == Nokogiri::XML::Element
          # only one node
          save_scene(node, chapter)
        else
          node.each do |scene|
            save_scene(scene, chapter)
          end
        end
      end
      compute_wc
    end
# Parse the document structure into chapters and scenes
Parse the document structure into chapters and scenes
Parse the document structure into chapters and scenes
def parse
      xml = File.read(scrivx)
      doc = Nokogiri::Slop(xml)
      binder_items = doc.ScrivenerProject.Binder.BinderItem
      manu = binder_items.detect { |el| el.Title.content == 'Manuscript' }
      chapter_nodes = manu.Children.BinderItem.select { |el| el.Title.content.match('Chapter') }
      chapter_nodes.each do |chapter_node|
        title = chapter_node.Title.content
        id = chapter_node['ID']
        chapter = Chapter.new(id, title)
        add_chapter(chapter)
        node = chapter_node.Children.BinderItem("[Type='Text']")
        if node.class == Nokogiri::XML::Element
          save_scene(node, chapter)
        else
          node.each do |scene|
            save_scene(scene, chapter)
          end
        end
      end
      compute_wc
    end
def parse xml = File . read ( scrivx ) doc = Nokogiri :: Slop ( xml ) binder_items = doc . ScrivenerProject . Binder . BinderItem manu = binder_items . detect { | el | el . Title . content == 'Manuscript' } chapter_nodes = manu . Children . BinderItem . select { | el | el . Title . content . match ( 'Chapter' ) } chapter_nodes . each do | chapter_node | title = chapter_node . Title . content id = chapter_node [ 'ID' ] chapter = Chapter . new ( id , title ) add_chapter ( chapter ) node = chapter_node . Children . BinderItem ( "[Type='Text']" ) if node . class == Nokogiri :: XML :: Element save_scene ( node , chapter ) else node . each do | scene | save_scene ( scene , chapter ) end end end compute_wc end
Parse the document structure into chapters and scenes
Parse the document structure into chapters and scenes
# parse the project and compute statistics # only one node