Class: Compostr::CustomFieldValue
- Inherits:
-
Object
- Object
- Compostr::CustomFieldValue
- Defined in:
- lib/compostr/custom_field_value.rb
Overview
Describe a Custom Field Value with optionally an id (corresponding to the WordPress data).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(id, key, value) ⇒ CustomFieldValue
constructor
A new instance of CustomFieldValue.
-
#to_hash ⇒ Object
Convert to hash that is consumable by RubyPress/Wordpress.
Constructor Details
#initialize(id, key, value) ⇒ CustomFieldValue
Returns a new instance of CustomFieldValue.
6 7 8 9 10 |
# File 'lib/compostr/custom_field_value.rb', line 6 def initialize id, key, value @id = id @key = key @value = value end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/compostr/custom_field_value.rb', line 4 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/compostr/custom_field_value.rb', line 4 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/compostr/custom_field_value.rb', line 4 def value @value end |
Instance Method Details
#to_hash ⇒ Object
Convert to hash that is consumable by RubyPress/Wordpress. Important that neither key nor value are present for custom field values that should be deleted in wordpress instance.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/compostr/custom_field_value.rb', line 15 def to_hash if @id hsh = { id: @id } hsh[:key] = @key if @key hsh[:value] = @value if @value hsh else hsh = {} hsh[:key] = @key if @key hsh[:value] = @value if @value hsh end end |