Class: Rabbit::SlideConfiguration

Inherits:
Object
  • Object
show all
Includes:
GetText, PathManipulatable
Defined in:
lib/rabbit/slide-configuration.rb

Constant Summary collapse

GEM_NAME_PREFIX =
"rabbit-slide"

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetText

included

Constructor Details

#initialize(logger = nil) ⇒ SlideConfiguration

Returns a new instance of SlideConfiguration.



49
50
51
52
# File 'lib/rabbit/slide-configuration.rb', line 49

def initialize(logger=nil)
  @logger = logger || Logger.default
  clear
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



46
47
48
# File 'lib/rabbit/slide-configuration.rb', line 46

def author
  @author
end

#base_nameObject

Returns the value of attribute base_name.



35
36
37
# File 'lib/rabbit/slide-configuration.rb', line 35

def base_name
  @base_name
end

#heightObject

Returns the value of attribute height.



48
49
50
# File 'lib/rabbit/slide-configuration.rb', line 48

def height
  @height
end

#idObject

Returns the value of attribute id.



34
35
36
# File 'lib/rabbit/slide-configuration.rb', line 34

def id
  @id
end

#licensesObject

Returns the value of attribute licenses.



40
41
42
# File 'lib/rabbit/slide-configuration.rb', line 40

def licenses
  @licenses
end

#loggerObject

Returns the value of attribute logger.



33
34
35
# File 'lib/rabbit/slide-configuration.rb', line 33

def logger
  @logger
end

#presentation_dateObject

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_timeObject

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_timeObject

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_idObject

Returns the value of attribute slideshare_id.



41
42
43
# File 'lib/rabbit/slide-configuration.rb', line 41

def slideshare_id
  @slideshare_id
end

#speaker_deck_idObject

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

#tagsObject

Returns the value of attribute tags.



36
37
38
# File 'lib/rabbit/slide-configuration.rb', line 36

def tags
  @tags
end

#versionObject



164
165
166
# File 'lib/rabbit/slide-configuration.rb', line 164

def version
  @version || default_version
end

#vimeo_idObject

Returns the value of attribute vimeo_id.



43
44
45
# File 'lib/rabbit/slide-configuration.rb', line 43

def vimeo_id
  @vimeo_id
end

#widthObject

Returns the value of attribute width.



47
48
49
# File 'lib/rabbit/slide-configuration.rb', line 47

def width
  @width
end

#youtube_idObject

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

#clearObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rabbit/slide-configuration.rb', line 86

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
end

#gem_nameObject



168
169
170
# File 'lib/rabbit/slide-configuration.rb', line 168

def gem_name
  "#{GEM_NAME_PREFIX}-#{@author.rubygems_user}-#{@id}"
end

#loadObject



66
67
68
69
70
71
72
73
74
# File 'lib/rabbit/slide-configuration.rb', line 66

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, $!.message])
end

#merge!(conf) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rabbit/slide-configuration.rb', line 105

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
end

#pathObject



172
173
174
# File 'lib/rabbit/slide-configuration.rb', line 172

def path
  "config.yaml"
end

#save(base_dir) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/rabbit/slide-configuration.rb', line 76

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_hashObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rabbit/slide-configuration.rb', line 130

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,
  }
  config["author"] = @author.to_hash if @author
  config
end

#to_yamlObject



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rabbit/slide-configuration.rb', line 151

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