Class: HTMLSchema::API::Attribute

Inherits:
HTMLSchema::Attribute show all
Defined in:
lib/html-schema/api/attribute.rb

Instance Attribute Summary

Attributes inherited from HTMLSchema::Attribute

#options, #required, #type, #value

Attributes inherited from Object

#_name, #as, #attributes, #classes, #parent, #source, #types

Instance Method Summary collapse

Methods inherited from HTMLSchema::Attribute

attribute?, #format, #initialize, #inspect, #to_object

Methods inherited from Object

#[], #attribute, #initialize, #inspect, #to_object, #type

Constructor Details

This class inherits a constructor from HTMLSchema::Attribute

Instance Method Details

#microdataObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/html-schema/api/attribute.rb', line 4

def microdata
  if @microdata.nil?
    object     = HTMLSchema.instance.microdata[parent]
    object     = object[_name] if object
    object     = false if object.blank?
    @microdata = object
  end
  
  @microdata
end

#microdata?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/html-schema/api/attribute.rb', line 15

def microdata?
  !!microdata
end

#microformatObject



19
20
21
22
23
24
25
26
27
# File 'lib/html-schema/api/attribute.rb', line 19

def microformat
  if @microformat.nil?
    object     = HTMLSchema.instance.microformat[parent]
    object     = object[_name] if object
    object     = false if object.blank?
    @microformat = object
  end
  @microformat
end

#microformat?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/html-schema/api/attribute.rb', line 29

def microformat?
  !!microformat
end

#to_hashObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/html-schema/api/attribute.rb', line 41

def to_hash
  if microdata? && microformat?
    to_microdata.merge(to_microformat)
  elsif microdata?
    to_microdata
  elsif microformat?
    to_microformat
  else
    {}
  end
end

#to_microdataObject



33
34
35
# File 'lib/html-schema/api/attribute.rb', line 33

def to_microdata
  microdata.to_hash
end

#to_microformatObject



37
38
39
# File 'lib/html-schema/api/attribute.rb', line 37

def to_microformat
  microformat.to_hash
end