Class: Mkmatter::Answers
- Inherits:
-
Object
- Object
- Mkmatter::Answers
- Defined in:
- lib/mkmatter/answers.rb
Instance Attribute Summary collapse
-
#answer_hash ⇒ Object
Returns the value of attribute answer_hash.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#date ⇒ Object
Returns the value of attribute date.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#file_format ⇒ Object
Returns the value of attribute file_format.
-
#matter ⇒ Object
readonly
Returns the value of attribute matter.
-
#published ⇒ Object
Returns the value of attribute published.
-
#slug_date ⇒ Object
Returns the value of attribute slug_date.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#dump ⇒ String
Dumps all file applicable metadata to a provided output.
-
#initialize(question_hash, publish) ⇒ Answers
constructor
A new instance of Answers.
-
#to_h ⇒ Hash
(also: #inspect)
Returns attribute ‘.matter`.
-
#to_h=(hash) ⇒ nil
Merges hash into attribute ‘.matter`.
Constructor Details
#initialize(question_hash, publish) ⇒ Answers
Returns a new instance of Answers.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mkmatter/answers.rb', line 12 def initialize(question_hash, publish) @title = question_hash[:title] @tags = question_hash[:tags] @categories = question_hash[:categories] Time.zone = question_hash[:time_zone] now = Time.zone.now @date = now.to_s @slug_date = now.strftime('%Y-%m-%d') @published = publish @file_format = question_hash[:file_format] @matter = { layout: question_hash[:layout], title: @title, categories: @categories, tags: @tags, date: @date, } @matter[:published] = @published if publish end |
Instance Attribute Details
#answer_hash ⇒ Object
Returns the value of attribute answer_hash.
8 9 10 |
# File 'lib/mkmatter/answers.rb', line 8 def answer_hash @answer_hash end |
#categories ⇒ Object
Returns the value of attribute categories.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def categories @categories end |
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/mkmatter/answers.rb', line 7 def date @date end |
#draft ⇒ Object
Returns the value of attribute draft.
7 8 9 |
# File 'lib/mkmatter/answers.rb', line 7 def draft @draft end |
#file_format ⇒ Object
Returns the value of attribute file_format.
9 10 11 |
# File 'lib/mkmatter/answers.rb', line 9 def file_format @file_format end |
#matter ⇒ Object (readonly)
Returns the value of attribute matter.
10 11 12 |
# File 'lib/mkmatter/answers.rb', line 10 def matter @matter end |
#published ⇒ Object
Returns the value of attribute published.
9 10 11 |
# File 'lib/mkmatter/answers.rb', line 9 def published @published end |
#slug_date ⇒ Object
Returns the value of attribute slug_date.
8 9 10 |
# File 'lib/mkmatter/answers.rb', line 8 def slug_date @slug_date end |
#tags ⇒ Object
Returns the value of attribute tags.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def title @title end |
Instance Method Details
#dump ⇒ String
Dumps all file applicable metadata to a provided output.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mkmatter/answers.rb', line 47 def dump custom_fields = nil hl = HighLine.new($stdin, $stderr, 80) # Custom matter if hl.agree('Do you want to add custom fields? (usable as {{LAYOUT_TYPE.FIELD}} in templates) ', true) hl.say('Your fields should be inputted as FIELD=>TEXT HERE') hl.say("Enter 'EOL' on a new line and press enter when you are done.") hl.say("<% HighLine.color('NOTE', :bold, :red) %>: Input is <% HighLine.color('NOT', :bold, :red) %> evaluated!") custom_fields = hl.ask('Fields?') do |q| q.gather = /^EOL$/ end end if custom_fields fields = Hash.new custom_fields.each do |field| field = field.split(/=>/) fields.store(field[0].to_s, field[1]) end self.to_h = fields elsif custom_fields.nil? hl.say('No extra fields were added.') else end self.to_h.stringify_keys.to_yaml(indentation: 2) '---' end |
#to_h ⇒ Hash Also known as: inspect
Returns attribute ‘.matter`
33 34 35 |
# File 'lib/mkmatter/answers.rb', line 33 def to_h @matter end |
#to_h=(hash) ⇒ nil
Returns merges hash into attribute ‘.matter`.
39 40 41 |
# File 'lib/mkmatter/answers.rb', line 39 def to_h=(hash) @matter.merge!(hash) end |