Class: MTIF

Inherits:
Object
  • Object
show all
Defined in:
lib/mtif.rb,
lib/mtif/posts.rb,
lib/mtif/version.rb

Overview

Defined Under Namespace

Classes: Post

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ MTIF

Returns a new instance of MTIF.



9
10
11
# File 'lib/mtif.rb', line 9

def initialize(content)
  @posts = content.slice_after(/^--------$/).map {|raw_post| MTIF::Post.new(raw_post)}
end

Instance Attribute Details

#postsObject

Returns the value of attribute posts.



7
8
9
# File 'lib/mtif.rb', line 7

def posts
  @posts
end

Class Method Details

.load_file(filename) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/mtif.rb', line 13

def self.load_file(filename)
  mtif_file = File.open(filename)
  mtif = MTIF.new(mtif_file.readlines)
  mtif_file.close

  mtif
end

Instance Method Details

#save_file(filename) ⇒ Object



25
26
27
28
29
# File 'lib/mtif.rb', line 25

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

#to_mtifObject



21
22
23
# File 'lib/mtif.rb', line 21

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