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.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#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? ⇒ Boolean
- #permalink? ⇒ Boolean
- #set(key, value) ⇒ Object
- #write_to_page(dir) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Record
Returns a new instance of Record.
8 9 10 11 12 |
# File 'lib/wax_tasks/record.rb', line 8 def initialize(hash) @hash = hash @pid = @hash.dig 'pid' @order = @hash.dig 'order' 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 |
#order ⇒ Object (readonly)
Returns the value of attribute order.
6 7 8 |
# File 'lib/wax_tasks/record.rb', line 6 def order @order 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
46 47 48 |
# File 'lib/wax_tasks/record.rb', line 46 def keep_only(fields) @hash.select! { |k, _v| fields.include? k } end |
#keys ⇒ Object
22 23 24 |
# File 'lib/wax_tasks/record.rb', line 22 def keys @hash.keys end |
#lunr_normalize_values ⇒ Object
16 17 18 |
# File 'lib/wax_tasks/record.rb', line 16 def lunr_normalize_values @hash.transform_values { |v| Utils.lunr_normalize v } end |
#order? ⇒ Boolean
40 41 42 |
# File 'lib/wax_tasks/record.rb', line 40 def order? @order.is_a? String end |
#permalink? ⇒ Boolean
34 35 36 |
# File 'lib/wax_tasks/record.rb', line 34 def permalink? @hash.key? 'permalink' end |
#set(key, value) ⇒ Object
28 29 30 |
# File 'lib/wax_tasks/record.rb', line 28 def set(key, value) @hash[key] = value end |
#write_to_page(dir) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wax_tasks/record.rb', line 52 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 |