Class: ToFactory::Parsing::File
- Inherits:
-
Object
- Object
- ToFactory::Parsing::File
- Defined in:
- lib/to_factory/parsing/file.rb
Constant Summary collapse
- EmptyFileException =
Class.new ArgumentError
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(contents) ⇒ File
constructor
A new instance of File.
- #parser ⇒ Object
Constructor Details
#initialize(contents) ⇒ File
Returns a new instance of File.
25 26 27 |
# File 'lib/to_factory/parsing/file.rb', line 25 def initialize(contents) @contents = contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
12 13 14 |
# File 'lib/to_factory/parsing/file.rb', line 12 def contents @contents end |
Class Method Details
.from_file(filename) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/to_factory/parsing/file.rb', line 18 def self.from_file(filename) contents = ::File.read filename rescue nil raise EmptyFileException.new "Invalid file #{filename}" if contents.to_s.strip.length == 0 new(contents) end |
.parse(filename) ⇒ Object
14 15 16 |
# File 'lib/to_factory/parsing/file.rb', line 14 def self.parse(filename) from_file(filename).parse end |
Instance Method Details
#parser ⇒ Object
29 30 31 |
# File 'lib/to_factory/parsing/file.rb', line 29 def parser @parser ||= Syntax.new(@contents) end |