Module: OpenGraphReader::Object
- Included in:
- Article, Book, Music, Og, OpenGraphReader::Og::Audio, OpenGraphReader::Og::Image, OpenGraphReader::Og::Locale, OpenGraphReader::Og::Video, Profile, Video
- Defined in:
- lib/open_graph_reader/object.rb,
lib/open_graph_reader/object/dsl.rb,
lib/open_graph_reader/object/registry.rb,
lib/open_graph_reader/object/dsl/types.rb
Overview
This module provides the base functionality for all OpenGraph objects and makes the DSL methods for describing them available when included.
Defined Under Namespace
Modules: DSL Classes: Registry
Instance Attribute Summary collapse
-
#children ⇒ {String => Array<String, Object>}
readonly
private
Properties on this object that are arrays.
-
#content ⇒ String?
If the namespace this object represents had a value, it is available here.
-
#properties ⇒ {String => String, Object}
readonly
private
Regular properties on this object.
Instance Method Summary collapse
-
#[](name) ⇒ String, Object
private
Get a property on this object.
-
#[]=(name, value) ⇒ Object
private
Set the property to the given value.
-
#has_property?(name) ⇒ Bool
Whether this object has the given property.
-
#initialize ⇒ Object
Create a new object.
-
#to_s ⇒ String
Returns #content if available.
Instance Attribute Details
#children ⇒ {String => Array<String, Object>} (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Properties on this object that are arrays.
38 39 40 |
# File 'lib/open_graph_reader/object.rb', line 38 def children @children end |
#content ⇒ String?
If the namespace this object represents had a value, it is available here
26 27 28 |
# File 'lib/open_graph_reader/object.rb', line 26 def content @content end |
#properties ⇒ {String => String, Object} (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Regular properties on this object
32 33 34 |
# File 'lib/open_graph_reader/object.rb', line 32 def properties @properties end |
Instance Method Details
#[](name) ⇒ String, Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
right error?
Get a property on this object.
72 73 74 75 |
# File 'lib/open_graph_reader/object.rb', line 72 def [] name raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}" unless has_property? name public_send name.to_s #properties[name.to_s] end |
#[]=(name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the property to the given value.
83 84 85 86 87 88 89 |
# File 'lib/open_graph_reader/object.rb', line 83 def []= name, value if has_property?(name) public_send "#{name}=", value elsif OpenGraphReader.config.strict raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}" end end |
#has_property?(name) ⇒ Bool
Whether this object has the given property
51 52 53 |
# File 'lib/open_graph_reader/object.rb', line 51 def has_property? name self.class.available_properties.include? name.to_s end |
#initialize ⇒ Object
Create a new object. If your class overrides this don’t forget to call super.
42 43 44 45 |
# File 'lib/open_graph_reader/object.rb', line 42 def initialize @properties = {} @children = Hash.new {|h, k| h[k] = [] } end |
#to_s ⇒ String
Returns #content if available.
94 95 96 |
# File 'lib/open_graph_reader/object.rb', line 94 def to_s content || super end |