Class: Mozenda::Infrastructure::File
- Inherits:
-
Object
- Object
- Mozenda::Infrastructure::File
- Defined in:
- lib/mozenda/infrastructure/file.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(file_path) ⇒ File
constructor
A new instance of File.
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(file_path) ⇒ File
Returns a new instance of File.
4 5 6 |
# File 'lib/mozenda/infrastructure/file.rb', line 4 def initialize file_path @path = ::Pathname.new(file_path) end |
Instance Method Details
#content ⇒ Object
19 20 21 |
# File 'lib/mozenda/infrastructure/file.rb', line 19 def content @content ||= @path.read end |
#to_h ⇒ Object
15 16 17 |
# File 'lib/mozenda/infrastructure/file.rb', line 15 def to_h @hash ||= ::Nori.new.parse(content) end |
#validate! ⇒ Object
8 9 10 11 12 13 |
# File 'lib/mozenda/infrastructure/file.rb', line 8 def validate! item_list = to_h["ItemList"] raise InvalidFileFormatException.new("Missing XML root tag: 'ItemList'") if item_list.nil? items = item_list["Item"] raise InvalidFileFormatException.new("Missing XML tag: 'Item'") if items.nil? end |