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.
-
#extra_fields ⇒ Object
Returns the value of attribute extra_fields.
-
#file_format ⇒ Object
Returns the value of attribute file_format.
-
#matter ⇒ Object
Returns the value of attribute matter.
-
#published ⇒ Object
Returns the value of attribute published.
-
#slug_date ⇒ Object
Returns the value of attribute slug_date.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #[](arg) ⇒ Object
-
#initialize(question_hash, publish, include_post_fields = true) ⇒ Answers
constructor
A new instance of Answers.
-
#to_h ⇒ Hash
Returns attribute ‘.matter`.
-
#to_h=(hash) ⇒ nil
Merges hash into attribute ‘.matter`.
- #to_yaml(*args, **kwargs) ⇒ Object
Constructor Details
#initialize(question_hash, publish, include_post_fields = true) ⇒ Answers
Returns a new instance of Answers.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mkmatter/answers.rb', line 9 def initialize(question_hash, publish, include_post_fields = true) @title = question_hash[:title] @layout = question_hash[:layout] if @layout == 'post' include_post_fields = true end @tags = question_hash[:tags] if question_hash[:tags].nil? == false @categories = question_hash[:categories] if question_hash[:categories].nil? == false if include_post_fields == true || @layout == 'post' Time.zone = get_time_zone_full(Time.now.getlocal) || 'Eastern Time (US & Canada)' end # Time.zone = question_hash[:time_zone] || Time.now.zone @now = Time.zone.now || Time.now.getlocal @date = @now.to_s if include_post_fields == true @slug_date = @now.strftime('%Y-%m-%d') if include_post_fields == true @published = publish @file_format = question_hash[:file_format] @extra_fields = question_hash[:extra_fields] if question_hash[:summary] @summary = question_hash[:summary] unless question_hash[:summary].empty? end @matter = { layout: @layout, title: @title } if @layout == 'post' || include_post_fields @matter[:tags] = @tags if @tags @matter[:categories] = @categories if @categories @matter[:summary] = @summary if @summary @matter[:date] = @date end if @draft @matter[:draft] = @draft end if @extra_fields @matter.merge!(@extra_fields) end @matter[:published] = @published if publish end |
Instance Attribute Details
#answer_hash ⇒ Object
Returns the value of attribute answer_hash.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 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.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def date @date end |
#draft ⇒ Object
Returns the value of attribute draft.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def draft @draft end |
#extra_fields ⇒ Object
Returns the value of attribute extra_fields.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def extra_fields @extra_fields end |
#file_format ⇒ Object
Returns the value of attribute file_format.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def file_format @file_format end |
#matter ⇒ Object
Returns the value of attribute matter.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def matter @matter end |
#published ⇒ Object
Returns the value of attribute published.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def published @published end |
#slug_date ⇒ Object
Returns the value of attribute slug_date.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def slug_date @slug_date end |
#summary ⇒ Object
Returns the value of attribute summary.
6 7 8 |
# File 'lib/mkmatter/answers.rb', line 6 def summary @summary 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
#[](arg) ⇒ Object
56 57 58 |
# File 'lib/mkmatter/answers.rb', line 56 def [](arg) self.instance_variable_get("@#{arg}") end |
#to_h ⇒ Hash
Returns attribute ‘.matter`
52 53 54 |
# File 'lib/mkmatter/answers.rb', line 52 def to_h @matter end |
#to_h=(hash) ⇒ nil
Returns merges hash into attribute ‘.matter`.
61 62 63 |
# File 'lib/mkmatter/answers.rb', line 61 def to_h=(hash) @matter.merge!(hash) end |
#to_yaml(*args, **kwargs) ⇒ Object
65 66 67 |
# File 'lib/mkmatter/answers.rb', line 65 def to_yaml(*args, **kwargs) @matter.stringify_keys.to_yaml(*args, **kwargs) end |