class Mozenda::Infrastructure::File

Public Class Methods

new(file_path) click to toggle source
# File lib/mozenda/infrastructure/file.rb, line 4
def initialize file_path
  @path = ::Pathname.new(file_path)
end

Public Instance Methods

content() click to toggle source
# File lib/mozenda/infrastructure/file.rb, line 19
def content
  @content ||= @path.read
end
to_h() click to toggle source
# File lib/mozenda/infrastructure/file.rb, line 15
def to_h
  @hash ||= ::Nori.new.parse(content)
end
validate!() click to toggle source
# 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