Class: Aspire::Object::Base
- Inherits:
-
Object
- Object
- Aspire::Object::Base
- Includes:
- Util
- Defined in:
- lib/aspire/object/base.rb
Overview
The base class for Aspire API objects
Direct Known Subclasses
Constant Summary collapse
- STRIP_HTML =
Aspire properties containing HTML markup will have the markup stripped
if STRIP_HTML = true"#{without format suffix (.html, .json etc.)}"
true
Constants included from Util
Instance Attribute Summary collapse
-
#factory ⇒ Aspire::Object::Factory
The factory for creating Aspire::Object instances.
-
#uri ⇒ String
The URI of the object.
Instance Method Summary collapse
-
#get_boolean(property, data, single: true) ⇒ Boolean+
Returns a Boolean property value.
-
#get_date(property, data, single: true) ⇒ DateTime+
Returns a DateTime instance for a timestamp property.
-
#get_property(property, data, is_url: false, single: true) {|value, type| ... } ⇒ Object+
Returns the value of a property.
-
#initialize(uri, factory) ⇒ void
constructor
Initialises a new Aspire::Object instance.
-
#to_s ⇒ String
Returns a string representation of the APIObject instance (the URI).
Methods included from Util
#child_url?, #duration, #id_from_uri, #item?, #linked_data, #linked_data_path, #list?, #list_url?, #module?, #parent_url?, #parse_url, #resource?, #section?, #url_for_comparison, #url_path, #user?
Constructor Details
#initialize(uri, factory) ⇒ void
Initialises a new Aspire::Object instance
31 32 33 34 35 |
# File 'lib/aspire/object/base.rb', line 31 def initialize(uri, factory) self.factory = factory # Normalise the URL to the linked data form self.uri = factory ? factory.cache.linked_data_url(uri) : uri end |
Instance Attribute Details
#factory ⇒ Aspire::Object::Factory
Returns the factory for creating Aspire::Object instances.
20 21 22 |
# File 'lib/aspire/object/base.rb', line 20 def factory @factory end |
#uri ⇒ String
Returns the URI of the object.
24 25 26 |
# File 'lib/aspire/object/base.rb', line 24 def uri @uri end |
Instance Method Details
#get_boolean(property, data, single: true) ⇒ Boolean+
Returns a Boolean property value
44 45 46 47 48 |
# File 'lib/aspire/object/base.rb', line 44 def get_boolean(property, data, single: true) get_property(property, data, single: single) do |value, _type| value ? true : false end end |
#get_date(property, data, single: true) ⇒ DateTime+
Returns a DateTime instance for a timestamp property
57 58 59 60 61 |
# File 'lib/aspire/object/base.rb', line 57 def get_date(property, data, single: true) get_property(property, data, single: single) do |value, _type| DateTime.parse(value) end end |
#get_property(property, data, is_url: false, single: true) {|value, type| ... } ⇒ Object+
Returns the value of a property
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/aspire/object/base.rb', line 75 def get_property(property, data, is_url: false, single: true, &block) values = data ? data[property] : nil if values.is_a?(Array) values = values.map do |value| get_property_value(value, is_url: is_url, &block) end single ? values[0] : values else value = get_property_value(values, is_url: is_url, &block) single ? value : [value] end end |
#to_s ⇒ String
Returns a string representation of the APIObject instance (the URI)
90 91 92 |
# File 'lib/aspire/object/base.rb', line 90 def to_s uri.to_s end |