Class: HTMLSchema::Object
- Inherits:
-
Object
- Object
- HTMLSchema::Object
- Defined in:
- lib/html-schema/object.rb
Direct Known Subclasses
API::Object, Attribute, Microdata::Object, Microformat::Object
Instance Attribute Summary collapse
-
#_name ⇒ Object
Returns the value of attribute _name.
-
#as ⇒ Object
Returns the value of attribute as.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#source ⇒ Object
Returns the value of attribute source.
-
#types ⇒ Object
Returns the value of attribute types.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #attribute(name, options = {}) ⇒ Object
-
#initialize(name, options = {}, &block) ⇒ Object
constructor
A new instance of Object.
- #inspect ⇒ Object
- #to_object ⇒ Object
- #type(name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Object
Returns a new instance of Object.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/html-schema/object.rb', line 6 def initialize(name, = {}, &block) @_name = name @attributes = {} @types = {} @parent = [:parent] @as = [:as] @as ||= @parent ? @parent.as : name @classes = Array(as).map(&:to_s) # inherit parent attributes @parent.attributes.each do |key, attribute| self.attribute key, attribute.value end if @parent instance_eval(&block) if block_given? end |
Instance Attribute Details
#_name ⇒ Object
Returns the value of attribute _name.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def _name @_name end |
#as ⇒ Object
Returns the value of attribute as.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def as @as end |
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def attributes @attributes end |
#classes ⇒ Object
Returns the value of attribute classes.
4 5 6 |
# File 'lib/html-schema/object.rb', line 4 def classes @classes end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def parent @parent end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def source @source end |
#types ⇒ Object
Returns the value of attribute types.
3 4 5 |
# File 'lib/html-schema/object.rb', line 3 def types @types end |
Instance Method Details
#[](key) ⇒ Object
35 36 37 |
# File 'lib/html-schema/object.rb', line 35 def [](key) attributes[key] end |
#attribute(name, options = {}) ⇒ Object
23 24 25 |
# File 'lib/html-schema/object.rb', line 23 def attribute(name, = {}) create_attribute name, end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/html-schema/object.rb', line 31 def inspect "#<#{self.class.name} name: #{_name.inspect}, attributes: #{attributes.inspect} parent: #{(parent.present? ? parent._name : nil).inspect}, types: #{types.keys.inspect}>" end |
#to_object ⇒ Object
39 40 41 42 43 |
# File 'lib/html-schema/object.rb', line 39 def to_object result = to_hash.merge(:attributes => attributes.keys.inject({}) { |hash, key| hash[key] = attributes[key].to_object ; hash }) result[:parent] = parent._name if parent result end |
#type(name, options = {}, &block) ⇒ Object
27 28 29 |
# File 'lib/html-schema/object.rb', line 27 def type(name, = {}, &block) create_type name, , &block end |