class Locca::CollectionBuilder

Public Class Methods

new(file_manager, parser) click to toggle source
# File lib/locca/collection_builder.rb, line 29
def initialize(file_manager, parser)
    @file_manager = file_manager
    @parser = parser
end

Public Instance Methods

collection_at_path(path) click to toggle source
# File lib/locca/collection_builder.rb, line 34
def collection_at_path(path)
    collection = nil

    @file_manager.open(path, 'rb:BOM|UTF-8:UTF-8') do |file|
        collection = collection_from_datastring(file.read())
        collection.name = File.basename(path, File.extname(path))
    end

    return collection
end
collection_from_datastring(datastring) click to toggle source
# File lib/locca/collection_builder.rb, line 45
def collection_from_datastring(datastring)
    collection = Collection.new()
    @parser.parse(datastring) do |key, value, comment|
        collection.add_item(CollectionItem.new(key, value, comment))
    end
    return collection
end