Sha256: e6bb5ca91cdea767337045600ce3b949bdc527cfdae791bd75d41fcb2e0ead3f
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true # Generate blog post/article fixture data, with embedded marker tag pairs. module ArticleFixtureGen # Details of data built by the generator. module Data # Details of generated Article and internal details thereof. class ArticleContent def initialize(config:, ¶s_builder) @config = config @paras_builder = paras_builder @str = nil self end def to_s return @str if @str @str = Internals.wrap_content(content) end private attr_reader :config, :paras_builder def content paragraphs.join("\n") end def paragraph(sentence_count) paras_builder.call sentence_count end def paragraphs Array.new(para_count) { paragraph(sentence_count) } end def para_count rand(para_count_range) end def para_count_range config.para_count_min..config.para_count_max end def sentence_count rand(sentence_count_range) end def sentence_count_range config.sent_count_min..config.sent_count_max end # Stateless methods and supporting constants. module Internals CONTENT_WRAPPER = ['<div class="article">', '</div>'].freeze def self.wrap_content(inner_content) CONTENT_WRAPPER.join inner_content end end private_constant :Internals end # class ArticleFixtureGen::Data::ArticleContent end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
article_fixture_gen-0.1.2 | lib/article_fixture_gen/data/article_content.rb |
article_fixture_gen-0.1.1 | lib/article_fixture_gen/data/article_content.rb |