Class: WordpressApi::Mash
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- WordpressApi::Mash
- Defined in:
- lib/wordpress_api/mash.rb
Class Method Summary collapse
-
.from_json(json_string) ⇒ Object
a simple helper to convert a json string to a Mash.
Instance Method Summary collapse
- #timestamp ⇒ Object
-
#to_date ⇒ Object
returns a Date if we have year, month and day, and no conflicting key.
Class Method Details
.from_json(json_string) ⇒ Object
a simple helper to convert a json string to a Mash
8 9 10 11 |
# File 'lib/wordpress_api/mash.rb', line 8 def self.from_json(json_string) result_hash = ::MultiJson.decode(json_string) new(result_hash) end |
Instance Method Details
#timestamp ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/wordpress_api/mash.rb', line 22 def value = self['timestamp'] if value.kind_of? Integer value = value / 1000 if value > 9999999999 Time.at(value) else value end end |
#to_date ⇒ Object
returns a Date if we have year, month and day, and no conflicting key
14 15 16 17 18 19 20 |
# File 'lib/wordpress_api/mash.rb', line 14 def to_date if !self.has_key?('to_date') && contains_date_fields? Date.civil(self.year, self.month, self.day) else super end end |