Class: ActivityStreams::Base
- Inherits:
-
Object
- Object
- ActivityStreams::Base
- Includes:
- Validator, AttrOptional, AttrRequired
- Defined in:
- lib/activitystreams/base.rb
Direct Known Subclasses
Activity, Collection, ExtProperties::Mood, MediaLink, Object, Object::Place::Address, Object::Place::GeoLocation, Verb
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #validate_attributes! ⇒ Object
Methods included from Validator
#to_float, #to_integer, #to_iri, #to_time, #validate_attribute!
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 |
# File 'lib/activitystreams/base.rb', line 5 def initialize(attributes = {}) (required_attributes + optional_attributes).each do |_attr_| self.send :"#{_attr_}=", attributes[_attr_] end validate_attributes! end |
Instance Method Details
#as_json(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/activitystreams/base.rb', line 16 def as_json( = {}) (required_attributes + optional_attributes).inject({}) do |hash, _attr_| _value_ = self.send _attr_ hash.merge!( _attr_.to_s.camelize(:lower).to_sym => case _value_ when Symbol, Addressable::URI _value_.to_s when Time _value_.iso8601 else _value_ end ) end.delete_if do |k,v| v.blank? end end |
#validate_attributes! ⇒ Object
12 13 14 |
# File 'lib/activitystreams/base.rb', line 12 def validate_attributes! attr_missing! end |