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.
-
#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.
-
#slideshare_id ⇒ Object
Returns the value of attribute slideshare_id.
-
#speaker_deck_id ⇒ Object
Returns the value of attribute speaker_deck_id.
-
#tags ⇒ Object
Returns the value of attribute tags.
- #version ⇒ Object
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.
38 39 40 41 |
# File 'lib/rabbit/slide-configuration.rb', line 38 def initialize(logger=nil) @logger = logger || Logger.default clear end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
37 38 39 |
# File 'lib/rabbit/slide-configuration.rb', line 37 def @author end |
#base_name ⇒ Object
Returns the value of attribute base_name.
34 35 36 |
# File 'lib/rabbit/slide-configuration.rb', line 34 def base_name @base_name 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.
35 36 37 |
# File 'lib/rabbit/slide-configuration.rb', line 35 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.
34 35 36 |
# File 'lib/rabbit/slide-configuration.rb', line 34 def presentation_date @presentation_date end |
#slideshare_id ⇒ Object
Returns the value of attribute slideshare_id.
35 36 37 |
# File 'lib/rabbit/slide-configuration.rb', line 35 def @slideshare_id end |
#speaker_deck_id ⇒ Object
Returns the value of attribute speaker_deck_id.
35 36 37 |
# File 'lib/rabbit/slide-configuration.rb', line 35 def speaker_deck_id @speaker_deck_id end |
#tags ⇒ Object
Returns the value of attribute tags.
34 35 36 |
# File 'lib/rabbit/slide-configuration.rb', line 34 def @tags end |
#version ⇒ Object
109 110 111 |
# File 'lib/rabbit/slide-configuration.rb', line 109 def version @version || default_version end |
Instance Method Details
#clear ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rabbit/slide-configuration.rb', line 63 def clear @id = nil @base_name = nil @tags = [] @presentation_date = nil @version = nil @licenses = [] @slideshare_id = nil @speaker_deck_id = nil @author = nil end |
#gem_name ⇒ Object
113 114 115 |
# File 'lib/rabbit/slide-configuration.rb', line 113 def gem_name "#{GEM_NAME_PREFIX}-#{@author.rubygems_user}-#{@id}" end |
#load ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/rabbit/slide-configuration.rb', line 43 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, $!.]) end |
#merge!(conf) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rabbit/slide-configuration.rb', line 75 def merge!(conf) @id ||= conf["id"] @base_name ||= conf["base_name"] @presentation_date ||= conf["presentation_date"] @version ||= conf["version"] @slideshare_id ||= conf["slideshare_id"] @speaker_deck_id ||= conf["speaker_deck_id"] @tags |= (conf["tags"] || []) @licenses |= (conf["licenses"] || []) @author = AuthorConfiguration.new(@logger) @author.merge!(conf["author"] || {}) end |
#path ⇒ Object
117 118 119 |
# File 'lib/rabbit/slide-configuration.rb', line 117 def path "config.yaml" end |
#save(base_dir) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/rabbit/slide-configuration.rb', line 53 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rabbit/slide-configuration.rb', line 90 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, } config["author"] = @author.to_hash if @author config end |
#to_yaml ⇒ Object
105 106 107 |
# File 'lib/rabbit/slide-configuration.rb', line 105 def to_yaml to_hash.to_yaml end |