Class: WaxTasks::Record
- Inherits:
-
Object
- Object
- WaxTasks::Record
- Defined in:
- lib/wax_tasks/record.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Record
constructor
A new instance of Record.
- #keep_only(fields) ⇒ Object
- #keys ⇒ Object
- #lunr_normalize_values ⇒ Object
- #order ⇒ Object
- #order? ⇒ Boolean
- #permalink? ⇒ Boolean
-
#set(key, value) ⇒ Object
- PATCH
-
rename ‘fullwidth’ to ‘full’ to (1) avoid breaking wax_iiif with special ‘full’ variant label (2) avoid breaking wax_theme which still expects ‘full’ to provide an image path this can be deprecated when a new version of wax_theme looks for another fullsize key.
- #write_to_page(dir) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Record
Returns a new instance of Record.
8 9 10 11 |
# File 'lib/wax_tasks/record.rb', line 8 def initialize(hash) @hash = hash @pid = @hash.dig 'pid' end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
6 7 8 |
# File 'lib/wax_tasks/record.rb', line 6 def hash @hash end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/wax_tasks/record.rb', line 6 def pid @pid end |
Instance Method Details
#keep_only(fields) ⇒ Object
53 54 55 |
# File 'lib/wax_tasks/record.rb', line 53 def keep_only(fields) @hash.select! { |k, _v| fields.include? k } end |
#keys ⇒ Object
25 26 27 |
# File 'lib/wax_tasks/record.rb', line 25 def keys @hash.keys end |
#lunr_normalize_values ⇒ Object
19 20 21 |
# File 'lib/wax_tasks/record.rb', line 19 def lunr_normalize_values @hash.transform_values { |v| Utils.lunr_normalize v } end |
#order ⇒ Object
13 14 15 |
# File 'lib/wax_tasks/record.rb', line 13 def order @hash.dig 'order' end |
#order? ⇒ Boolean
47 48 49 |
# File 'lib/wax_tasks/record.rb', line 47 def order? !order.to_s.empty? end |
#permalink? ⇒ Boolean
41 42 43 |
# File 'lib/wax_tasks/record.rb', line 41 def permalink? @hash.key? 'permalink' end |
#set(key, value) ⇒ Object
- PATCH
-
rename ‘fullwidth’ to ‘full’ to
(1) avoid breaking wax_iiif with special ‘full’ variant label (2) avoid breaking wax_theme which still expects ‘full’ to provide an image path this can be deprecated when a new version of wax_theme looks for another fullsize key
34 35 36 37 |
# File 'lib/wax_tasks/record.rb', line 34 def set(key, value) key = 'full' if key == 'fullwidth' @hash[key] = value end |
#write_to_page(dir) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wax_tasks/record.rb', line 59 def write_to_page(dir) raise Error::MissingPid if @pid.nil? path = "#{dir}/#{Utils.slug(@pid)}.md" if File.exist? path 0 else FileUtils.mkdir_p File.dirname(path) File.open(path, 'w') { |f| f.puts "#{@hash.to_yaml}---" } 1 end end |