Sha256: e4149c0e8b7eae1efe1b19b73c3f48fd09498f72e9d44d33dab540d951f75e92

Contents?: true

Size: 618 Bytes

Versions: 1

Compression:

Stored size: 618 Bytes

Contents

require "mtif/version"
require "mtif/posts"

# Based on https://movabletype.org/documentation/appendices/import-export-format.html

class MTIF
  attr_accessor :posts

  def initialize(content)
    @posts = content.slice_after(/^--------$/).map {|raw_post| MTIF::Post.new(raw_post)}
  end
  
  def self.load_file(filename)
    mtif_file = File.open(filename)
    mtif = MTIF.new(mtif_file.readlines)
    mtif_file.close
    
    mtif
  end

  def to_mtif
    posts.map(&:to_mtif).join
  end

  def save_file(filename)
    mtif_file = File.open(filename, 'w')
    mtif_file << self.to_mtif
    mtif_file.close
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mtif-0.0.1 lib/mtif.rb