Class: Skemata::Node
- Inherits:
-
Object
- Object
- Skemata::Node
- Defined in:
- lib/skemata/node.rb
Constant Summary collapse
- ALLOWED_OPTS =
%i[type root_object].freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#decorate(name, *args, &block) ⇒ Object
Decorate the node with a new property (as delegated by method_missing).
-
#initialize(opts = {}) ⇒ Node
constructor
Prepares internal data hash and assigns locals.
Constructor Details
#initialize(opts = {}) ⇒ Node
Prepares internal data hash and assigns locals
12 13 14 15 16 |
# File 'lib/skemata/node.rb', line 12 def initialize(opts = {}) ALLOWED_OPTS.each { |o| instance_variable_set("@#{o}", opts[o]) } @data = { '@type' => type } @data['@context'] = 'https://schema.org' if opts.fetch(:is_root, true) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
32 33 34 |
# File 'lib/skemata/node.rb', line 32 def data @data end |
Instance Method Details
#decorate(name, *args, &block) ⇒ Object
Decorate the node with a new property (as delegated by method_missing)
25 26 27 28 29 30 |
# File 'lib/skemata/node.rb', line 25 def decorate(name, *args, &block) # Draw another node return route_block(name, *args, &block) if block.present? # Or populate the hash data[attify_token(name)] = extract(args.first || name.to_sym) end |