class Rabbit::SlideConfiguration

Constants

GEM_NAME_PREFIX

Attributes

author[RW]
base_name[RW]
id[RW]
licenses[RW]
logger[RW]
presentation_date[RW]
slideshare_id[RW]
speaker_deck_id[RW]
tags[RW]
ustream_id[RW]
version[W]
vimeo_id[RW]
youtube_id[RW]

Public Class Methods

new(logger=nil) click to toggle source
# File lib/rabbit/slide-configuration.rb, line 43
def initialize(logger=nil)
  @logger = logger || Logger.default
  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 68
def clear
  @id                = nil
  @base_name         = nil
  @tags              = []
  @presentation_date = nil
  @version           = nil
  @licenses          = []
  @slideshare_id     = nil
  @speaker_deck_id   = nil
  @ustream_id        = nil
  @vimeo_id          = nil
  @youtube_id        = nil
  @author            = nil
end
gem_name() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 127
def gem_name
  "#{GEM_NAME_PREFIX}-#{@author.rubygems_user}-#{@id}"
end
load() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 48
def load
  return unless File.exist?(path)
  conf = YAML.load(File.read(path))
  clear
  merge!(conf)
rescue
  format = _("Failed to read slide configuration: %s: %s")
  @logger.error(format % [path, $!.message])
end
merge!(conf) click to toggle source
# File lib/rabbit/slide-configuration.rb, line 83
def merge!(conf)
  @id                = conf["id"]                || @id
  @base_name         = conf["base_name"]         || @base_name
  @presentation_date = conf["presentation_date"] || @presentation_date
  @version           = conf["version"]           || @version
  @slideshare_id     = conf["slideshare_id"]     || @slideshare_id
  @speaker_deck_id   = conf["speaker_deck_id"]   || @speaker_deck_id
  @ustream_id        = conf["ustream_id"]        || @ustream_id
  @vimeo_id          = conf["vimeo_id"]          || @vimeo_id
  @youtube_id        = conf["youtube_id"]        || @youtube_id

  @tags              |=  (conf["tags"] || [])
  @licenses          |=  (conf["licenses"] || [])

  @author ||= AuthorConfiguration.new(@logger)
  @author.merge!(conf["author"] || {})
end
path() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 131
def path
  "config.yaml"
end
save(base_dir) click to toggle source
# File lib/rabbit/slide-configuration.rb, line 58
def save(base_dir)
  config_path = File.join(base_dir, path)
  create_file(config_path) do |conf_file|
    conf_file.print(to_yaml)
  end
rescue
  format = _("Failed to write slide configuration: %s: %s")
  @logger.error(format % [config_path, $!.message])
end
to_hash() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 101
def to_hash
  config = {
    "id"                => @id,
    "base_name"         => @base_name,
    "tags"              => @tags,
    "presentation_date" => @presentation_date,
    "version"           => version,
    "licenses"          => @licenses,
    "slideshare_id"     => @slideshare_id,
    "speaker_deck_id"   => @speaker_deck_id,
    "ustream_id"        => @ustream_id,
    "vimeo_id"          => @vimeo_id,
    "youtube_id"        => @youtube_id,
  }
  config["author"] = @author.to_hash if @author
  config
end
to_yaml() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 119
def to_yaml
  to_hash.to_yaml
end
version() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 123
def version
  @version || default_version
end

Private Instance Methods

default_version() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 145
def default_version
  date = parsed_presentation_date
  if date
    date.strftime("%Y.%m.%d")
  else
    "1.0.0"
  end
end
parsed_presentation_date() click to toggle source
# File lib/rabbit/slide-configuration.rb, line 136
def parsed_presentation_date
  return nil if @presentation_date.nil?
  begin
    Time.parse(@presentation_date)
  rescue ArgumentError
    nil
  end
end