Class: HatenablogPublisher::FixedContent::Ad
- Inherits:
-
Object
- Object
- HatenablogPublisher::FixedContent::Ad
- Defined in:
- lib/hatenablog_publisher/fixed_content/ad.rb
Constant Summary collapse
- MAX_AD_SIZE =
3
Instance Method Summary collapse
- #format_body ⇒ Object
-
#initialize(category, options) ⇒ Ad
constructor
A new instance of Ad.
- #sample_items ⇒ Object
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, ) @mapping = YAML.load_file(.ad_file) @options = @category = category end |
Instance Method Details
#format_body ⇒ Object
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_items ⇒ Object
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 |