Class: Mozenda::Infrastructure::File

Inherits:
Object
  • Object
show all
Defined in:
lib/mozenda/infrastructure/file.rb

Instance Method Summary collapse

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

#contentObject



19
20
21
# File 'lib/mozenda/infrastructure/file.rb', line 19

def content
  @content ||= @path.read
end

#to_hObject



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