Class: TM::Parse::PlainText

Inherits:
Object
  • Object
show all
Defined in:
lib/tm/parse/plain_text.rb

Defined Under Namespace

Classes: Attribute, Row

Constant Summary collapse

@@data =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, name) ⇒ PlainText

Returns a new instance of PlainText.



7
8
9
10
11
# File 'lib/tm/parse/plain_text.rb', line 7

def initialize(file, name)
	self.file, self.name = file, name
	@@data[file] ||= {}
	@@data[file][name] ||= []
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



5
6
7
# File 'lib/tm/parse/plain_text.rb', line 5

def file
  @file
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/tm/parse/plain_text.rb', line 5

def headers
  @headers
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tm/parse/plain_text.rb', line 5

def name
  @name
end

Class Method Details

.[](file, name) ⇒ Object



13
14
15
16
# File 'lib/tm/parse/plain_text.rb', line 13

def self.[](file, name)
	parse(file) unless @@data[file]
	(@@data[file] && @@data[file][name]) || []
end

Instance Method Details

#add_row(values) ⇒ Object



18
19
20
21
22
23
# File 'lib/tm/parse/plain_text.rb', line 18

def add_row(values)
	values = values.sub(/^\|/,'').sub(/\|\s*$/,'').split(' | ').map(&:strip)
	return(set_header(values)) if headers.nil?

	@@data[file][name].push PlainText::Row.new(values, headers)
end