class HatenablogPublisher::FixedContent::Ad

Constants

MAX_AD_SIZE

Public Class Methods

new(category, options) click to toggle source
# File lib/hatenablog_publisher/fixed_content/ad.rb, line 6
def initialize(category, options)
  @mapping = YAML.load_file(options.ad_file)
  @options = options
  @category = category
end

Public Instance Methods

format_body() click to toggle source
# File lib/hatenablog_publisher/fixed_content/ad.rb, line 12
def format_body
  "\n\n\n" + CGI.escapeHTML(sample_items.join("\n"))
end
sample_items() click to toggle source
# File lib/hatenablog_publisher/fixed_content/ad.rb, line 16
def sample_items
  @mapping.slice(*@category).map { |_, v| v }.flatten.sample(MAX_AD_SIZE).map do |r|
    r[@options.ad_type]
  end
end