Class: CRFPP::Model

Inherits:
Object
  • Object
show all
Includes:
Filelike
Defined in:
lib/crfpp/model.rb

Instance Attribute Summary collapse

Attributes included from Filelike

#path

Instance Method Summary collapse

Methods included from Filelike

#read, #write

Constructor Details

#initialize(path = nil) ⇒ Model

Returns a new instance of Model.



8
9
10
# File 'lib/crfpp/model.rb', line 8

def initialize(path = nil)
  @data, @path = '', path
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/crfpp/model.rb', line 6

def data
  @data
end

Instance Method Details

#data?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/crfpp/model.rb', line 25

def data?
  data && !data.empty?
end

#openObject



12
13
14
15
# File 'lib/crfpp/model.rb', line 12

def open
  @data = read
  self
end

#saveObject



17
18
19
# File 'lib/crfpp/model.rb', line 17

def save
  save_to(path)
end

#save_to(file) ⇒ Object



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

def save_to(file)
  write(file, data? ? data : read)
end