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.
-
#initialize ⇒ Object
Create a new object.
-
#property?(name) ⇒ Bool
Whether this object has the given property.
-
#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.
37 38 39 |
# File 'lib/open_graph_reader/object.rb', line 37 def children @children end |
#content ⇒ String?
If the namespace this object represents had a value, it is available here
25 26 27 |
# File 'lib/open_graph_reader/object.rb', line 25 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
31 32 33 |
# File 'lib/open_graph_reader/object.rb', line 31 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.
70 71 72 73 |
# File 'lib/open_graph_reader/object.rb', line 70 def [] name raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}" unless property? name public_send 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.
81 82 83 84 85 86 87 |
# File 'lib/open_graph_reader/object.rb', line 81 def []= name, value if property?(name) public_send "#{name}=", value elsif OpenGraphReader.config.strict raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}" end end |
#initialize ⇒ Object
Create a new object. If your class overrides this don’t forget to call super
.
40 41 42 43 |
# File 'lib/open_graph_reader/object.rb', line 40 def initialize @properties = {} @children = Hash.new {|h, k| h[k] = [] } end |
#property?(name) ⇒ Bool
Whether this object has the given property
49 50 51 |
# File 'lib/open_graph_reader/object.rb', line 49 def property? name self.class.available_properties.include? name.to_s end |
#to_s ⇒ String
Returns #content if available.
92 93 94 |
# File 'lib/open_graph_reader/object.rb', line 92 def to_s content || super end |