Class: Munge::Conglomerate::ItemFactory
- Inherits:
-
Object
- Object
- Munge::Conglomerate::ItemFactory
- Defined in:
- lib/munge/conglomerate/item_factory.rb,
lib/munge/conglomerate/item_factory/content_parser.rb,
lib/munge/conglomerate/item_factory/item_identifier.rb
Defined Under Namespace
Classes: ContentParser, ItemIdentifier
Instance Method Summary collapse
-
#build(relpath:, content:, frontmatter: {}, stat: nil) ⇒ Object
Builds an Item.
-
#initialize(text_extensions:, ignore_extensions:) ⇒ ItemFactory
constructor
A new instance of ItemFactory.
-
#parse(relpath:, content:, stat: nil) ⇒ Object
Parses frontmatter and builds an Item, given a text string.
Constructor Details
#initialize(text_extensions:, ignore_extensions:) ⇒ ItemFactory
Returns a new instance of ItemFactory.
6 7 8 9 10 |
# File 'lib/munge/conglomerate/item_factory.rb', line 6 def initialize(text_extensions:, ignore_extensions:) @text_extensions = text_extensions @item_identifier = ItemIdentifier.new(remove_extensions: ignore_extensions) end |
Instance Method Details
#build(relpath:, content:, frontmatter: {}, stat: nil) ⇒ Object
Builds an Item
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/munge/conglomerate/item_factory.rb', line 18 def build(relpath:, content:, frontmatter: {}, stat: nil) type = item_file_type(relpath) id = @item_identifier.call(relpath) Munge::Item.new( relpath: relpath, content: content, frontmatter: frontmatter, stat: stat, type: type, id: id ) end |
#parse(relpath:, content:, stat: nil) ⇒ Object
Parses frontmatter and builds an Item, given a text string
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/munge/conglomerate/item_factory.rb', line 41 def parse(relpath:, content:, stat: nil) normalized_content, normalized_frontmatter = if item_file_type(relpath) == :text parsed = ContentParser.new(content) [parsed.content, parsed.frontmatter] else [content, {}] end build( relpath: relpath, content: normalized_content, frontmatter: normalized_frontmatter, stat: stat ) end |