Class: HTMLSchema::Attribute
- Defined in:
- lib/html-schema/attribute.rb
Direct Known Subclasses
HTMLSchema::API::Attribute, Microdata::Attribute, Microformat::Attribute
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#required ⇒ Object
Returns the value of attribute required.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Object
#_name, #as, #attributes, #classes, #parent, #source, #types
Class Method Summary collapse
Instance Method Summary collapse
-
#format(value) ⇒ Object
ISO 8601 date format.
-
#initialize(name, options = {}, &block) ⇒ Attribute
constructor
A new instance of Attribute.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #to_object ⇒ Object
Methods inherited from Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/html-schema/attribute.rb', line 5 def initialize(name, = {}, &block) @_name = name @value = @parent = [:parent] @as = [:as] || name @classes = Array(as).map(&:to_s) @required = [:required] == true @type = [:type] || :string @options = .except(:as, :parent, :required, :type) @options.each do |key, value| @options[key] = value.to_s end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/html-schema/attribute.rb', line 3 def @options end |
#required ⇒ Object
Returns the value of attribute required.
3 4 5 |
# File 'lib/html-schema/attribute.rb', line 3 def required @required end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/html-schema/attribute.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/html-schema/attribute.rb', line 3 def value @value end |
Class Method Details
.attribute? ⇒ Boolean
47 48 49 |
# File 'lib/html-schema/attribute.rb', line 47 def attribute? true end |
Instance Method Details
#format(value) ⇒ Object
ISO 8601 date format
25 26 27 28 29 30 31 32 |
# File 'lib/html-schema/attribute.rb', line 25 def format(value) case type when :date ::Date.parse(value) else value.to_s end end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/html-schema/attribute.rb', line 20 def inspect "#<#{self.class.name} name: #{_name.inspect}, value: #{value.inspect}>" end |
#to_hash ⇒ Object
38 39 40 |
# File 'lib/html-schema/attribute.rb', line 38 def to_hash {} end |
#to_object ⇒ Object
42 43 44 |
# File 'lib/html-schema/attribute.rb', line 42 def to_object to_hash.merge(:type => type) end |