Class: ToFactory::Parsing::File

Inherits:
Object
  • Object
show all
Defined in:
lib/to_factory/parsing/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ File

Returns a new instance of File.



24
25
26
# File 'lib/to_factory/parsing/file.rb', line 24

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/to_factory/parsing/file.rb', line 11

def contents
  @contents
end

Class Method Details

.from_file(filename) ⇒ Object



17
18
19
20
21
22
# File 'lib/to_factory/parsing/file.rb', line 17

def self.from_file(filename)
  contents = ::File.read filename rescue nil
  raise ArgumentError.new "Invalid file #{filename}"  if contents.to_s.length == 0

  new(contents)
end

.parse(filename) ⇒ Object



13
14
15
# File 'lib/to_factory/parsing/file.rb', line 13

def self.parse(filename)
  from_file(filename).parse
end

Instance Method Details

#parserObject



28
29
30
# File 'lib/to_factory/parsing/file.rb', line 28

def parser
  @parser ||= parser_klass.new(@contents)
end