Class: Rabbit::SlideConfiguration
- Inherits:
-
Object
- Object
- Rabbit::SlideConfiguration
- Includes:
- GetText, PathManipulatable
- Defined in:
- lib/rabbit/slide-configuration.rb
Constant Summary collapse
- GEM_NAME_PREFIX =
"rabbit-slide"
Constants included from GetText
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#base_name ⇒ Object
Returns the value of attribute base_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#licenses ⇒ Object
Returns the value of attribute licenses.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#presentation_date ⇒ Object
Returns the value of attribute presentation_date.
-
#presentation_end_time ⇒ Object
Returns the value of attribute presentation_end_time.
-
#presentation_start_time ⇒ Object
Returns the value of attribute presentation_start_time.
-
#slideshare_id ⇒ Object
Returns the value of attribute slideshare_id.
-
#source_code_uri ⇒ Object
Returns the value of attribute source_code_uri.
-
#speaker_deck_id ⇒ Object
Returns the value of attribute speaker_deck_id.
-
#tags ⇒ Object
Returns the value of attribute tags.
- #version ⇒ Object
-
#vimeo_id ⇒ Object
Returns the value of attribute vimeo_id.
-
#width ⇒ Object
Returns the value of attribute width.
-
#youtube_id ⇒ Object
Returns the value of attribute youtube_id.
Instance Method Summary collapse
- #clear ⇒ Object
- #gem_name ⇒ Object
-
#initialize(logger = nil) ⇒ SlideConfiguration
constructor
A new instance of SlideConfiguration.
- #load ⇒ Object
- #merge!(conf) ⇒ Object
- #path ⇒ Object
- #save(base_dir) ⇒ Object
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
Methods included from GetText
Constructor Details
#initialize(logger = nil) ⇒ SlideConfiguration
Returns a new instance of SlideConfiguration.
50 51 52 53 |
# File 'lib/rabbit/slide-configuration.rb', line 50 def initialize(logger=nil) @logger = logger || Logger.default clear end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
46 47 48 |
# File 'lib/rabbit/slide-configuration.rb', line 46 def @author end |
#base_name ⇒ Object
Returns the value of attribute base_name.
35 36 37 |
# File 'lib/rabbit/slide-configuration.rb', line 35 def base_name @base_name end |
#height ⇒ Object
Returns the value of attribute height.
48 49 50 |
# File 'lib/rabbit/slide-configuration.rb', line 48 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
34 35 36 |
# File 'lib/rabbit/slide-configuration.rb', line 34 def id @id end |
#licenses ⇒ Object
Returns the value of attribute licenses.
40 41 42 |
# File 'lib/rabbit/slide-configuration.rb', line 40 def licenses @licenses end |
#logger ⇒ Object
Returns the value of attribute logger.
33 34 35 |
# File 'lib/rabbit/slide-configuration.rb', line 33 def logger @logger end |
#presentation_date ⇒ Object
Returns the value of attribute presentation_date.
37 38 39 |
# File 'lib/rabbit/slide-configuration.rb', line 37 def presentation_date @presentation_date end |
#presentation_end_time ⇒ Object
Returns the value of attribute presentation_end_time.
39 40 41 |
# File 'lib/rabbit/slide-configuration.rb', line 39 def presentation_end_time @presentation_end_time end |
#presentation_start_time ⇒ Object
Returns the value of attribute presentation_start_time.
38 39 40 |
# File 'lib/rabbit/slide-configuration.rb', line 38 def presentation_start_time @presentation_start_time end |
#slideshare_id ⇒ Object
Returns the value of attribute slideshare_id.
41 42 43 |
# File 'lib/rabbit/slide-configuration.rb', line 41 def @slideshare_id end |
#source_code_uri ⇒ Object
Returns the value of attribute source_code_uri.
49 50 51 |
# File 'lib/rabbit/slide-configuration.rb', line 49 def source_code_uri @source_code_uri end |
#speaker_deck_id ⇒ Object
Returns the value of attribute speaker_deck_id.
42 43 44 |
# File 'lib/rabbit/slide-configuration.rb', line 42 def speaker_deck_id @speaker_deck_id end |
#tags ⇒ Object
Returns the value of attribute tags.
36 37 38 |
# File 'lib/rabbit/slide-configuration.rb', line 36 def @tags end |
#version ⇒ Object
168 169 170 |
# File 'lib/rabbit/slide-configuration.rb', line 168 def version @version || default_version end |
#vimeo_id ⇒ Object
Returns the value of attribute vimeo_id.
43 44 45 |
# File 'lib/rabbit/slide-configuration.rb', line 43 def vimeo_id @vimeo_id end |
#width ⇒ Object
Returns the value of attribute width.
47 48 49 |
# File 'lib/rabbit/slide-configuration.rb', line 47 def width @width end |
#youtube_id ⇒ Object
Returns the value of attribute youtube_id.
44 45 46 |
# File 'lib/rabbit/slide-configuration.rb', line 44 def youtube_id @youtube_id end |
Instance Method Details
#clear ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rabbit/slide-configuration.rb', line 87 def clear @id = nil @base_name = nil @tags = [] @presentation_date = nil @presentation_start_time = nil @presentation_end_time = nil @version = nil @licenses = [] @slideshare_id = nil @speaker_deck_id = nil @vimeo_id = nil @youtube_id = nil @author = nil @width = 800 @height = 600 @source_code_uri = nil end |
#gem_name ⇒ Object
172 173 174 |
# File 'lib/rabbit/slide-configuration.rb', line 172 def gem_name "#{GEM_NAME_PREFIX}-#{@author.rubygems_user}-#{@id}" end |
#load ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/rabbit/slide-configuration.rb', line 67 def load return unless File.exist?(path) conf = YAMLLoader.load(File.read(path)) clear merge!(conf) rescue format = _("Failed to read slide configuration: %s: %s") @logger.error(format % [path, $!.]) end |
#merge!(conf) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rabbit/slide-configuration.rb', line 107 def merge!(conf) @id = conf["id"] || @id @base_name = conf["base_name"] || @base_name self.presentation_date = conf["presentation_date"] || @presentation_date self.presentation_start_time = conf["presentation_start_time"] || @presentation_start_time self.presentation_end_time = conf["presentation_end_time"] || @presentation_end_time @version = conf["version"] || @version @slideshare_id = conf["slideshare_id"] || @slideshare_id @speaker_deck_id = conf["speaker_deck_id"] || @speaker_deck_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"] || {}) @width = conf["width"] || @width @height = conf["height"] || @height @source_code_uri = conf["source_code_uri"] || @source_code_uri end |
#path ⇒ Object
176 177 178 |
# File 'lib/rabbit/slide-configuration.rb', line 176 def path "config.yaml" end |
#save(base_dir) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/rabbit/slide-configuration.rb', line 77 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, $!.]) end |
#to_hash ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rabbit/slide-configuration.rb', line 133 def to_hash config = { "id" => @id, "base_name" => @base_name, "tags" => @tags, "presentation_date" => @presentation_date, "presentation_start_time" => @presentation_start_time, "presentation_end_time" => @presentation_end_time, "version" => version, "licenses" => @licenses, "slideshare_id" => @slideshare_id, "speaker_deck_id" => @speaker_deck_id, "vimeo_id" => @vimeo_id, "youtube_id" => @youtube_id, "width" => @width, "height" => @height, "source_code_uri" => @source_code_uri, } config["author"] = @author.to_hash if @author config end |
#to_yaml ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rabbit/slide-configuration.rb', line 155 def to_yaml hash = to_hash hash.each do |key, value| case value when Date hash[key] = value.strftime("%Y-%m-%d") when Time hash[key] = value.iso8601 end end hash.to_yaml end |