Class: HatenablogPublisher::FixedContent::Ad

Inherits:
Object
  • Object
show all
Defined in:
lib/hatenablog_publisher/fixed_content/ad.rb

Constant Summary collapse

MAX_AD_SIZE =
3

Instance Method Summary collapse

Constructor Details

#initialize(category, options) ⇒ Ad

Returns a new instance of Ad.



6
7
8
9
10
# 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

Instance Method Details

#format_bodyObject



12
13
14
# File 'lib/hatenablog_publisher/fixed_content/ad.rb', line 12

def format_body
  "\n\n\n" + CGI.escapeHTML(sample_items.join("\n"))
end

#sample_itemsObject



16
17
18
19
20
# 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