Class: Imagetools::Config
- Inherits:
-
Object
- Object
- Imagetools::Config
- Defined in:
- lib/imagetools/imagefilter.rb
Constant Summary collapse
- FILENAME_SEARCH =
's (\d+)-(\d+)-(\d+) (\d+)\.(\d+)\.(\d+)'- FILENAME_REPLACE =
's_\1\2\3_\4\5\6'- RESIZE_WIDTH =
1280
Instance Attribute Summary collapse
-
#filename_replace1 ⇒ Object
Returns the value of attribute filename_replace1.
-
#filename_replace2 ⇒ Object
Returns the value of attribute filename_replace2.
-
#filename_replace3 ⇒ Object
Returns the value of attribute filename_replace3.
-
#filename_search1 ⇒ Object
Returns the value of attribute filename_search1.
-
#filename_search2 ⇒ Object
Returns the value of attribute filename_search2.
-
#filename_search3 ⇒ Object
Returns the value of attribute filename_search3.
-
#resize_width ⇒ Object
Returns the value of attribute resize_width.
Class Method Summary collapse
Instance Method Summary collapse
- #filename_patterns ⇒ Object
- #init_default ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
38 39 |
# File 'lib/imagetools/imagefilter.rb', line 38 def initialize end |
Instance Attribute Details
#filename_replace1 ⇒ Object
Returns the value of attribute filename_replace1.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_replace1 @filename_replace1 end |
#filename_replace2 ⇒ Object
Returns the value of attribute filename_replace2.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_replace2 @filename_replace2 end |
#filename_replace3 ⇒ Object
Returns the value of attribute filename_replace3.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_replace3 @filename_replace3 end |
#filename_search1 ⇒ Object
Returns the value of attribute filename_search1.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_search1 @filename_search1 end |
#filename_search2 ⇒ Object
Returns the value of attribute filename_search2.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_search2 @filename_search2 end |
#filename_search3 ⇒ Object
Returns the value of attribute filename_search3.
47 48 49 |
# File 'lib/imagetools/imagefilter.rb', line 47 def filename_search3 @filename_search3 end |
#resize_width ⇒ Object
Returns the value of attribute resize_width.
50 51 52 |
# File 'lib/imagetools/imagefilter.rb', line 50 def resize_width @resize_width end |
Class Method Details
.config_value(yaml, section, key, require) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/imagetools/imagefilter.rb', line 28 def self.config_value(yaml, section, key, require) return nil unless yaml return nil unless yaml[section] value = yaml[section][key] if require && (value.nil? || value.empty?) raise RuntimeError, "#{section}:#{key}: is empty" end value end |
.create_from_yaml(yaml) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/imagetools/imagefilter.rb', line 14 def self.create_from_yaml(yaml) config = Config.new config.filename_search1 = config_value(yaml, "filename", "search1", false) config.filename_replace1 = config_value(yaml, "filename", "replace1", false) config.filename_search2 = config_value(yaml, "filename", "search2", false) config.filename_replace2 = config_value(yaml, "filename", "replace2", false) config.filename_search3 = config_value(yaml, "filename", "search3", false) config.filename_replace3 = config_value(yaml, "filename", "replace3", false) config.resize_width = config_value(yaml, "resize", "width", false) config.init_default config end |
Instance Method Details
#filename_patterns ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/imagetools/imagefilter.rb', line 52 def filename_patterns [ [@filename_search1, @filename_replace1], [@filename_search2, @filename_replace2], [@filename_search3, @filename_replace3], ] end |
#init_default ⇒ Object
41 42 43 44 45 |
# File 'lib/imagetools/imagefilter.rb', line 41 def init_default @filename_search1 ||= FILENAME_SEARCH @filename_replace1 ||= FILENAME_REPLACE @resize_width ||= RESIZE_WIDTH end |