Class: Locca::CollectionBuilder
- Inherits:
-
Object
- Object
- Locca::CollectionBuilder
- Defined in:
- lib/locca/collection_builder.rb
Instance Method Summary collapse
- #collection_at_path(path) ⇒ Object
- #collection_from_datastring(datastring) ⇒ Object
-
#initialize(file_manager, parser) ⇒ CollectionBuilder
constructor
A new instance of CollectionBuilder.
Constructor Details
#initialize(file_manager, parser) ⇒ CollectionBuilder
Returns a new instance of CollectionBuilder.
29 30 31 32 |
# File 'lib/locca/collection_builder.rb', line 29 def initialize(file_manager, parser) @file_manager = file_manager @parser = parser end |
Instance Method Details
#collection_at_path(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
45 46 47 48 49 50 51 |
# 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 |